我想添加自定义通知到购物车,只要一个特定的产品(不是所有的产品)被添加到购物车。在Woocommerce中添加自定义通知到
我想首先检查数量,如果是1,那么我想显示通知以增加该产品的数量。我想通通过自己的东西从互联网上,我不认为我的解决方案是正确的:
add_action('wp', 'sp_custom_notice');
function sp_custom_notice() {
if (is_admin() && ! defined('DOING_AJAX')) return;
//to display notice only on cart page
if (! is_cart()) {
return;
}
global $product;
$product_id = method_exists($product, 'get_id') ? $product->get_id() : $product->id;
if($product_id == 15730){
//check for quantify if equal to 1 in cart
wc_clear_notices();
wc_add_notice(__("Add one more to get 50% off on 2nd product"), 'notice');
}
}
这将是巨大的,如果有人能帮助我在此。
再次感谢您为我节省了成本,您真棒... :) @loictheaztec – abdul