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?

1 Answer
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);

}

Leave a Reply

Your email address will not be published. Required fields are marked *