Reputation: 63
I am trying to move add to cart button under button(cart form) under the product image and leave variations where they are.
But with below hook variations are also going under the product image
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
Any way to make only button move under the image and not variations form.
Here is the screenshot:
Thank You
Tried following solution but no Luck
Try 1:
remove_action( 'woocommerce_single_variation', 'remove_variation', 10 );
function remove_variation(){
woocommerce_single_variation();
}
Try 2:
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
Upvotes: 2
Views: 2473
Reputation: 91
Default Actions:
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
Remove Default Actions:
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
Add Custom Action:
add_action( 'woocommerce_single_variation', 'new_custom_action', 5 );
function new_custom_action() {
echo 'TEST';
}
Upvotes: 2
Reputation: 108
If you look at the default variable template in woocommerce/templates/single-product/add-to-cart/variable.php you can see that for variable products, it combines both the variations drop-downs and the add to cart button together in the 'woocommerce_single_variation' hook:
/**
* woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
* @since 2.4.0
* @hooked woocommerce_single_variation - 10 Empty div for variation data.
* @hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
You can either customise this file within your theme to change this behaviour, or remove the woocommerce_single_variation function from this hook and add it somewhere else.
Upvotes: 0