Ecommerce Shopify WordPress Discussion

Hooking into WooCommerce notices after all notices have been generated, and before notices are printed and cleared

What is the correct WooCommerce hook to use to modify notices after cart validation is completed and before wc_print_notices() is executed? I’d like to customize the notices based on the totality of the notices to be printed. The woocommerce_add_error filter runs as each individual error message is generated. The wc_get_notices() function returns the notices up to but not including the current notice, and it’s impossible to know which iteration will be the last. I’m using a commercial cart plugin that replaces the woocommerce_before_cart action hook with a plugin_before_cart action hook. When I hook into this action with a priority of 9, wc_notice_count() == 0 and wc_get_notices() returns an empty array. When I hook into this action with a priority of 10, wc_print_notices() has already been executed. What’s the correct hook to use? Also, what is the replacement for the wc_add_notice() function? This comment from the CartController.php file indicates that the use of wc_add_notice() is to be discouraged: * This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture * notices and convert to wp errors instead.
You can't customize WooCommerce notices based on the totality of the notices to be printed, as the only hook available is "woocommerce_add_{$notice_type}" composite filter hook, that handle WooCommerce notices added via wc_add_notice() and wc_print_notice(). Note: This composite hook will not work If the notices were bulk added via wc_set_notices(). Does wc_add_notice() is going to be replaced? The CartController Class is part of StoreAPI, so only for WooCommerce Rest API. It discourages the use of wc_add_notice() in favor of NoticeHandler Class and all Classes located in StoreApi > Exceptions folder.

February 13, 2024

Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.