I'm fairly new to php. Working on a Wordpress site with WooCommerce. I added a notice that displays "Get free shipping on orders over $400...", and it works but when an item is removed or added to the cart it will display it multiple times. I would like it to only display once. Here's my code:
function sp_custom_notice() {
if ( ! is_cart() ) {
return;
}
$subtotal = WC()->cart->get_cart_subtotal();
$free_shipping_threshold = 400;
$notice_freeship = wc_add_notice( 'Get FREE shipping on orders over $400. Only valid in the US, not valid on bullets. <a href="https://bulletcentral.com/shipping/#promo">For more information, click here</a>', 'notice' );
if ( $subtotal < $free_shipping_threshold ) {
return $notice_freeship;
}
}
Which action do you add with the function sp_custom_notice? If you use
It will be called multiple times.
Try to hook up with other action:
So the notice will only shows one time when the checkout page is displayed.