1

I have a product description which is hooked into my product archive page in the following way by my theme (The7):

/**
 * display short desc hook.
 *
 * @hooked woocommerce_template_loop_rating - 5
 * @hooked woocommerce_template_loop_price - 10
 */
do_action( 'woocommerce_shop_loop_item_desc' );

In my template setting, I have a way of hiding this product description but this just hides the div with the description by using CSS display: none;

This is not good, as in the background, the description is still loaded & this has a negative effect on the performance of the page.

Therefore, I want to remove the action. I now did it by commenting it in the template file, but everytime I update the theme I'm screwed.

I tried to remove the action by adding the following code in my functions.php file (source: https://codex.wordpress.org/Function_Reference/remove_action) but this did not work:

/* Remove product description on product archive page */
remove_action( 'woocommerce_template_loop_rating','woocommerce_shop_loop_item_desc', 5);
remove_action( 'woocommerce_template_loop_price','woocommerce_shop_loop_item_desc', 10);

Anybody has an idea on how to correctly remove the action?

closed as off-topic by rudtek, Jacob Peattie, cjbj, Michal Mau, Rick Hellewell Apr 21 at 1:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • This seems the same as the topic here not sure why it wouldn't work for you. It's the only right method. – Karun Apr 5 at 9:12
  • Hi Karun, unfortunately, this does not work. The description is still loaded after adding the code to my functions.php file. – BarrieO Apr 5 at 9:27
  • I just realized in your code, you've set woocommerce_shop_loop_item_desc as a hook and to remove you used woocommerce_shop_loop_item_desc as function. You probably have some other function hooked into the woocommerce_shop_loop_item_desc. – Karun Apr 5 at 9:34
  • Can I give you some more information? The comment is not really helping me right now. Anyway, thank you for your time! – BarrieO Apr 5 at 9:41
  • 1
    Possible duplicate of Remove product description from product archive page – Akshat Apr 6 at 14:08
1

First thing, regarding your comment "everytime I update the theme I'm screwed" - you should always use a child theme when doing any customisations .

Second, your remove_action call is wrong. As per the documentation you've linked to already, it sates that the first argument is $tag and the second is $function_to_remove. Right now, your arguments are reversed.

So the correct call would be

/* Remove product description on product archive page */
remove_action( 'woocommerce_shop_loop_item_desc', 'woocommerce_template_loop_rating', 5);
remove_action( 'woocommerce_shop_loop_item_desc', 'woocommerce_template_loop_price', 10);

Update:

if the above solution doesn't work, it might be because the hook triggers after theme setup. In this case you can try the following :

add_action( 'after_setup_theme', 'my_remove_parent_theme_stuff', 0 );

function my_remove_parent_theme_stuff() {
    remove_action( 'woocommerce_shop_loop_item_desc', 'woocommerce_template_loop_rating', 5);
    remove_action( 'woocommerce_shop_loop_item_desc', 'woocommerce_template_loop_price', 10);

}
  • Hi, will try this tonight. Thanks for you answer 👊🏼. Indeed, I will remove the action in my functions.php file in the child theme so a theme update doesn’t overwrite this. I tried to do this before but as my call was incorrect, this did not work. How do you know what is the tag & what is the function in this case? I cannot seperate these very well. – BarrieO Apr 9 at 16:48
  • You can see in the comments above the do_action call what functions are hooked into it. Those hooks mean that when WordPress executes the woocommerce_shop_loop_item_desc action (function) it also calls the functions attached, in the order specified by the priority tag (5,10 etc - higher numbers are executed later). Hope this answers your question. – Mihai Apr 10 at 11:08
  • Hi Mihai, it answers my question, but I just tried this code on my website, but unfortunately it did not solve the issue :(. – BarrieO Apr 11 at 7:30
  • I've updated the answer in case the issue is with the timing of when the hooks get triggered. Try that and see if it works. – Mihai Apr 11 at 11:05
  • @BarrieO did the updated solution work ? If so, consider marking the question as answered. – Mihai Apr 15 at 7:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.