我的问题很简单,我只是不想让用户购物,除非用户没有登录。我还想在单个产品页面上显示特定消息“请先登录”,而不是“价格”或“添加到购物车”按钮。
我可以使用隐藏价格并添加到购物车功能。。。
if (!is_user_logged_in()) {
//Remove single product add to cart
remove_action(\'woocommerce_single_product_summary\', \'woocommerce_template_single_add_to_cart\', 30);
//Remove single product price
remove_action(\'woocommerce_single_product_summary\', \'woocommerce_template_single_price\', 10);
//Remove loop add to cart
remove_action(\'woocommerce_after_shop_loop_item\', \'woocommerce_template_loop_add_to_cart\');
//Remove loop price
remove_action(\'woocommerce_after_shop_loop_item_title\', \'woocommerce_template_loop_price\', 10);
}
如何在单个产品页面上显示消息“请先登录”,而不是“添加到购物车”按钮?
最合适的回答,由SO网友:aagjalpankaj 整理而成
这太容易了。我正在寻找这样的解决方案。。。
add_action(\'woocommerce_single_product_summary\', \'wl8ShowCustomMsgToGuest\', 10);
function wl8ShowCustomMsgToGuest(){
//
if (!is_user_logged_in()) {
$wc_ac_url = get_permalink(get_option(\'woocommerce_myaccount_page_id\'));
$msg = __(\'Please log in to see the price.\', \'wdmacspc\');
echo "<a href=\'$wc_ac_url\' class=\'button alt wl8-custom-btn\'>$msg</a>";
}
}