I wish to create a custom “notice-type” in Woocommerce.
The default templates used for messages are: ‘Success’, ‘Error‘ & ‘Info‘.
I have created a Template in the Override folder of my theme -> woocommerce/notices/”my-notice.php”
How should I override, in my theme “functions.php” file the default call for ‘Success‘ notice-type in product-page-> add-to-cart button after submit, to use the custom notice-type->”my-notice.php” ?
I know this answer is even later but I have found the exact solution you are looking for: a custom notice (type) for the add_to_cart action.
I couldn’t find it elsewhere so dropping it here just in case.
Creating the notice
First, let WooCommerce know you have a new notice_type available:
Second, create the notice template file in
/woocommerce/notices/mynotice.php
For example, copy the success notice and rename it and change the HTML a bit:
Now you can use your custom notice (anywhere) with the following code, just make sure the WC
woocommerce_output_all_notices
action has been hooked.Using custom notice for the add_to_cart action (overwrite)
So now we have our notice working, start looking for the correct filter to alter the default message (in this case the add-to-cart message).
Found here: WooCommerce Github v4.0, so let’s change it:
Or more advanced using a custom php template:
All done! Cheers.
EDIT:
If you just want this specific notice for a one time use you can skip the message_html filter and simply drop your message in the mynotice.php template. (less dynamic though)
I know this is a waaay late answer, but!
Try adding:
to your
function.php
. This will let WC add your custom type to the “notices-to-be-printed” list.Then use it as usual:
BTW, i would avoid special characters in your custom type name.
BTW! actually i’m not able to make it behave exactly like other types: i.e, when i update cart quantities, my custom notice-type message is not updated, while the original types are (?).
EDIT
Wow, i think i partially misnderstood your question..
Maybe the best way to achieve your goal is via CSS (if you want to change aspect) or using one of these hooks:
woocommerce_add_message
and'woocommerce_add_' . $notice_type
(if you want to modify/filter the message).