Site icon Qaisar Satti's Blogs

WooCommerce Notices or Message

This tutorial provides a straightforward solution on how to use a notice or message in WooCommerce. Through this tutorial, you will get to know about how to show the notice or message. There are three types of notices that can be used in WooCommerce; including Notice Message, Error Message, and Success Message. These notice messages can be utilized based on your requirements.

Let’s start with our example.

wc_add_notice function is used to add the notices in WooCommerce.

wc_add_notice({Write your notice message here}, {notice_type});

Different notice types are:
1. notice (blue color)
2. error (red color)
3. success ( green color)
You can print the notice by using the function.
[cc lang="php" tab_size="2" lines="40" escaped="true"]
wc_print_notices();

The html of notices can be stored in a variable to use further in Ajax
etc.

$notices = wc_print_notices( true );

Success Notice:

     wc_add_notice(3 × “Album” have been added to your cart., ‘success’);

Information Notice:

   wc_add_notice(‘Have a coupon?Click here to enter your code’, ‘notice’);

Error Notice:

  wc_add_notice(‘You cannot add that amount of "Album" to the cart because there is not enough stock (5 remaining)., ‘error);
Exit mobile version