1

我的 wp 网站中有一个 woocommerce,只有在用户登录时才需要显示价格和变化价格。我有这个代码,但只能使用价格,而不是变化价格......

add_filter('woocommerce_get_price_html','members_only_price');

function members_only_price($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 'Only <a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Registered Users</a> are able to view pricing.';
  }

}
4

0 回答 0