How to update messages on the Woocommerce shopping cart page? Hello everyone again, there was a problem updating the cart page.
The store sells products that are shipped in boxes, and there is a need for buyers to independently form their own "boxes" with various goods.
An eye-catching description and implementation here.
The question is the following - For example, we added the minimum amount of purchases in the store and decided to show this in a message on the cart page if the amount is not reached so that the person would not be able to go to the calculation page.
wc_add_notice( sprintf( __( "ΠΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½Π°Ρ ΡΡΠΌΠΌΠ° Π·Π°ΠΊΠ°Π·Π° %s $", 'woocommerce' ), $min_amount ), 'error' ); And everything works out well, except for one after adding products to the basket page, recalculation occurs by means of ajax, but the message does not disappear. If you disable ajax, you still need to click 2 times on the update button to correctly display the message (the amount in the message remembers the previous one).
It is necessary that the message disappears when the basket is recalculated. As I saw this is a fairly well-known problem who uses error messages to check the cart. Here is a rough code to understand the needs. Code only with the minimum amount of purchases.
<?php function woocommerce_check_cart_quantities_for_class() { global $woocommerce; $items = $woocommerce->cart->get_cart(); $subtotal = WC()->cart->get_cart_subtotal();// Π²ΡΠ²ΠΎΠ΄ΠΈΡΡΡΡ Π² Π²ΠΈΠ΄Π΅ "$0.936,00" -> 936$ $min_amount = "$0.050,00";// 50$ if($subtotal < $min_amount){ wc_add_notice( sprintf( __( "ΠΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½Π°Ρ ΡΡΠΌΠΌΠ° Π·Π°ΠΊΠ°Π·Π° %s $", 'woocommerce' ), $min_amount ), 'error' ); }else{ wc_add_notice( sprintf( __( "Π’Π΅ΠΏΠ΅ΡΡ Π²Ρ ΠΌΠΎΠΆΠ΅ΡΠ΅ ΠΏΠ΅ΡΠ΅Ρ
ΠΎΠ΄ΠΈΡΡ Π½Π° ΡΡΡΠ°Π½ΠΈΡΡ ΡΠ°ΡΡΠ΅ΡΠ°", 'woocommerce' ), ), 'notice' ); } } add_action( 'woocommerce_check_cart_items', 'woocommerce_check_cart_quantities_for_class' ); ?>