我有一些代码,阻止被显示在所有的产品,如果用户没有登录的价格。显示产品的价格,如果是会员或特定产品
我的问题是,我有1个产品这是免费的,我需要显示的价格,如果用户没有登录。
有人可以帮助我通过他的id目标该单一产品,并显示这个特殊的价格,即使用户没有登录。
这是我的原始代码funcions.php
阻止价格来回m显示,当用户没有登录时:
// Hide prices on public woocommerce (not logged in)
add_action('after_setup_theme','activate_filter') ;
function activate_filter(){
add_filter('woocommerce_get_price_html', 'show_price_logged');
}
function show_price_logged($price){
if(is_user_logged_in()){
return $price;
}
else
{
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
return '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">Call for pricing</a>';
}
}
谢谢。
您是否一直希望显示价格的固定产品ID? – rcadhikari
是的,我可以使用产品ID。 – MasterFuel
在wordpress dev中重新发布。回购... http://wordpress.stackexchange.com/questions/255438/have-woocommerce-show-product-price-if-id-when-not-logged-in – MasterFuel