Dismiss notices on item removal
-
Updating from woocommerce 2.6.* to 3 broke something on cart page as follows:
I have a custom function checking cart items, as some cannot be shipped to certain destinations. I add a notice with wc_add_notice(‘text’, ‘error’) to prevent checkout until the item is removed. Clicking the red x to remove the item does not trigger an update of the div containing the notice/error/success message, which still appears on screen on top of the “item remove, undo?”. Applying a coupon triggers correctly the div update and the deletion of messages. I assume this is AJAX related, as dequeueing wc_cart solves the issue.
Function code as follows (mostly copied from the interwebs, works fine with previous version of woocommerce!):function blocco_checkout() { // set the slug of the category for which we disallow checkout $cat1 = 'test'; // get destination state from shipping calculation form $paese = WC()->customer->get_shipping_country(); $paesi_no = array('AU','CA','JP','IT');//da integrare? //unico $stato non accettato al momento è Utah, quindi non importa fare array // get the product category $prod_cat1 = get_term_by( 'slug', $cat1, 'product_cat' ); // sanity check to prevent fatals if the term doesn't exist if ( is_wp_error( $prod_cat1 ) || is_wp_error( $prod_cat2 ) || is_wp_error($prod_cat3) ) { return; } $cat1_name = '<a href="' . get_term_link( $cat1, 'product_cat' ) . '">' . $prod_cat1->name . '</a>'; // check if this category is in the cart if ( prod_non_spedibili( $cat1 ) && $paese == 'IT' ) { // render a notice to explain why checkout is blocked //wc_add_notice( sprintf( 'Hi there! Looks like your cart contains products from the %1$s category – unfortunately they cannot be shipped to your destination.', $cat1_name ), 'error' ); wc_add_notice( sprintf( 'Hi there! Looks like your cart contains products from the %1$s category – unfortunately they cannot be shipped to your destination.', $cat1_name ), 'error' ); } } add_action( 'woocommerce_check_cart_items', 'blocco_checkout' );
- The topic ‘Dismiss notices on item removal’ is closed to new replies.