最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Remove action on product archive page

programmeradmin1浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

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: ) 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. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

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/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?

Share Improve this question edited Apr 6, 2019 at 18:48 rudtek 6,3835 gold badges30 silver badges52 bronze badges asked Apr 5, 2019 at 8:55 BarrieOBarrieO 992 silver badges12 bronze badges 5
  • This seems the same as the topic here not sure why it wouldn't work for you. It's the only right method. – Karun Commented Apr 5, 2019 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 Commented Apr 5, 2019 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 Commented Apr 5, 2019 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 Commented Apr 5, 2019 at 9:41
  • 1 Possible duplicate of Remove product description from product archive page – Akshat Commented Apr 6, 2019 at 14:08
Add a comment  | 

1 Answer 1

Reset to default 2

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

}
发布评论

评论列表(0)

  1. 暂无评论