Cannot remove the 'add to cart' button

Is there some reason that unhooking the ‘add to cart’ button function woocommerce_template_single_add_to_cart from the woocommerce_after_shop_loop_item action will not work?

remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

I’ve tried the above both with and without the priority setting, but the ‘add to cart’ button remains on the shop page…

Is something in PRO overriding this?

OK, it seems I’ve discovered the problem. PRO does indeed already unhook this function and then calls it again inside another function x_woocommerce_after_shop_loop_item_title.

I’ve solved the problem by unhooking the PRO function, and using my own.

For anyone else who needs to do the same, here is the full code I placed inside the child theme’s functions.php:

remove_action( 'woocommerce_before_shop_loop_item', 'x_woocommerce_before_shop_loop_item', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'x_woocommerce_after_shop_loop_item', 10 );
remove_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_before_shop_loop_item_title', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'x_woocommerce_after_shop_loop_item_title', 10 );

function my_woocommerce_before_shop_loop_item() {
  echo '<div class="entry-product">';
}

function my_woocommerce_after_shop_loop_item() {
  echo '</div>';
}

function my_woocommerce_before_shop_loop_item_title() {
  echo '<div class="entry-wrap" style="padding: 0;"><header class="entry-header">';
}

function my_woocommerce_after_shop_loop_item_title() {
  //woocommerce_template_loop_add_to_cart();
  echo '</header></div>';
}

add_action( 'woocommerce_before_shop_loop_item', 'my_woocommerce_before_shop_loop_item', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'my_woocommerce_after_shop_loop_item', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'my_woocommerce_before_shop_loop_item_title', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'my_woocommerce_after_shop_loop_item_title', 10 );

Due to the way Woocommerce hooks these functions, I found myself having to unhook more than the one function (it caused major formatting problems) and then add some inline CSS into my_woocommerce_before_shop_loop_item_title as shown above (15px of padding was being loaded from another stylesheet that I didn’t have time to mess around with).

To show the changes above, I have commented out the woocommerce_template_loop_add_to_cartfunction that is called inside my_woocommerce_after_shop_loop_item_title (just an edited version of the original x_woocommerce_after_shop_loop_item_title) which can actually just be deleted.

Hi @sguilliard,

Thank you for sharing the solution with us and we’re glad you sorted it out.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.