mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-03 12:12:25 +08:00
https://stackoverflow.com/questions/79659966/move-variation-description-from-original-location-to-woocommerce-single-product
27 lines
1.1 KiB
Text
27 lines
1.1 KiB
Text
// Rename the variation description variable name from the form data
|
|
add_filter( 'woocommerce_available_variation', 'filter_wc_available_variation_desscription', 10, 3);
|
|
function filter_wc_available_variation_desscription( $data, $product, $variation ) {
|
|
if ( isset($data['variation_description']) ) {
|
|
$data['descr'] = $data['variation_description']; // Set the variation description in a new variable
|
|
unset($data['variation_description']); // Remove original variation description variable
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
// Display the variation description to a new location
|
|
add_action( 'woocommerce_single_product_summary', 'displayed_varition_description', 25 );
|
|
function displayed_varition_description() {
|
|
global $product;
|
|
|
|
if ( ! $product->is_type( 'variable' ) ) {
|
|
return;
|
|
}
|
|
echo '<div class="variation-description"></div>';
|
|
|
|
wc_enqueue_js( "const d = '.variation-description';
|
|
$('form.cart').on('show_variation', function( event, data ) {
|
|
$(d).html(data.descr);
|
|
}).on('hide_variation', function( event, data ) {
|
|
$(d).html('');
|
|
});" );
|
|
}
|