1

I'd like to move my product's variation descriptions in Woocommerce beneath the add to cart button, and I can't find what hook I'm supposed to use. These are the variation's custom descriptions that load on selection in AJAX.

I'm able to hook another custom function beneath the add to cart button. So I think my problem is not knowing the name of the hook and/or if it's a hook versus a filter. I think it's either woocommerce_before_single_variation or woocommerce_before_add_to_cart_button.

Here's several attempts I've tried before with no luck in functions.php:

remove_action( 'woocommerce_after_single_variation','woocommerce_single_product_summary', 20 );
add_action( 'woocommerce_after_single_variation', 'woocommerce_single_product_summary',  9 );

//try #2
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_after_add_to_cart_button', 'woocommerce_single_variation', 35);

Thank you!

Sami Ahmed Siddiqui
  • 2,328
  • 1
  • 16
  • 29
Stevie
  • 189
  • 1
  • 2
  • 15

3 Answers3

2

The functionality I was looking for is included in WooCommerce 2.4 as a default but is not done on a hook. It's added by jQuery updating a div instead - which I found in woocommerce/js/assets/frontend/add-to-cart-variation.js. So I moved the div's location instead:

add_action ('woocommerce_after_single_variation', 'move_descriptions', 50);
function move_descriptions() {
    ?>
    <div class="woocommerce-variation-description" style="border: 1px solid transparent; height: auto;"></div>
    <?php
}
Stevie
  • 189
  • 1
  • 2
  • 15
0

I think this will do,

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20); 
add_action('woocommerce_after_add_to_cart_form', 'woocommerce_template_single_excerpt');

Only move Short description if product is variable

add_action('wp_head', 'move_short_desc_for_varition');
function move_short_desc_for_varition() {
    #
    global  $post;
    $product = get_product( $post->ID );
    if( $product->is_type( 'variable' ) ){ 
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20); 
        add_action('woocommerce_after_add_to_cart_form', 'woocommerce_template_single_excerpt');
    }
}
silver
  • 4,433
  • 1
  • 18
  • 30
  • I tried this, and I'm getting duplicate descriptions now. See [here](http://www.cchcollection.com.php53-13.ord1-1.websitetestlink.com/product/kenan-jacket) . Leads me to think that the remove_action call isn't working but the add_action call is – Stevie Dec 03 '15 at 17:25
  • ```woocommerce_template_single_excerpt``` is the product description hook on ```woocommerce_single_product_summary``` reference can be found on ```/woocommerce/templates/content-single-product.php``` line 53, checkout the demo http://demo2.woothemes.com/storefront/product/navy-floral-dress/ the product description is wrap with ```
    ``` while yours is not, which simply means the additional description that is showing is not loaded by woocommerce default,
    – silver Dec 03 '15 at 20:05
  • I realized that the product I linked you earlier had a short description displaying below the "Add to Cart" button, and made it appear that it was duplicating. Now that I've removed it, the code above isn't working. I tracked the div it is wrapped in to `/woocommerce/templates/singe-product/add-to-cart/variable.php` line 44. It's called `single_variation_wrap` , which is also where the hooks for single variation products are listed. – Stevie Dec 04 '15 at 00:03
  • what I'm saying is the first description showing on your single product page is not from woocommerce default template but probably fired on a hook somewhere, as the default description is wrap with ```
    ```
    – silver Dec 04 '15 at 03:19
  • I have tried this with all plugins but WC turned off and Twenty Fifteen as the default template and it's still showing up the unique variable product descriptions in `
    ` div. Is there something else with hooks that I'm missing?
    – Stevie Dec 04 '15 at 04:00
  • you sure you're using latest woocommerce without template modification, you can try a clean set-up and compare it with your current set-up – silver Dec 04 '15 at 08:00
  • Rereading my initial post, I think I'm explaining things imprecisely. I'm trying to move the variation descriptions (that are customized for a product variation and load via AJAX when you change selections) below the "Add to Cart" button. I've updated the main question to reflect this! – Stevie Dec 04 '15 at 15:25
  • Ajax is never been a default functionality that display the description, you need to dig into that function which is connected to ajax request and edit/change/remove where the custom description display is being hooked and fired via ajax – silver Dec 04 '15 at 18:52
  • For anyone else stumbling upon this, when you remove a hook you need to match the priority exactly otherwise it won't work. – Kadament May 13 '22 at 09:42
0

The problem is in the priority of the remove hook.

I give you an example (this work for me):

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 15 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );

Pay attention and try with differents priorities.

MatCas
  • 773
  • 8
  • 19