我想添加自定義通知到購物車,只要一個特定的產品(不是所有的產品)被添加到購物車。在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