【发布时间】:2018-03-10 06:33:36
【问题描述】:
我正在开发的网站要求您登录才能查看价格,而我一直在使用插件来执行此操作。然而,我只是被扔了一个曲线球,告诉我网站上的一个特定类别必须始终显示价格,无论用户是否登录。
看起来插件使用了
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
和
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
删除价格。这就是我尝试为特定类别的产品重新添加价格的方式:
function make_surplus_price_always_visible(){
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
if ( in_array( 'surplus-allison-parts', $categories ) && !is_user_logged_in()) {
?>
<script>
alert('product in surplus');
</script>
<?php
//add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
}
}
add_action('woocommerce_after_shop_loop_item_title', 'make_surplus_price_always_visible', 50);
但它不会加回价格。 jQuery 警报正在工作,因此满足“if”语句要求不是问题。
如何才能重新添加特定类别的产品价格?
【问题讨论】:
-
所以基本上你需要在用户登录特定类别时显示产品的价格。我说对了吗?
-
目前所有价格均针对已登录用户显示。如果用户退出特定类别,我需要显示产品价格。困难的部分是所有价格都通过插件隐藏了注销用户。 @AkshayShah
标签: php wordpress woocommerce categories price