I'm trying to figure out where WooCommerce creates it's messages for when there is a success, error or notice in WooCommerce. I want to edit those messages to fit the scenario more neatly and also edit the HTML. Where are these messages located and how do I edit them?
相关问题
- Display product ACF field value in Woocommerce tra
- Adding a custom button after add to cart button in
- How to add a “active” class to a carousel first el
- Setting custom order statuses as valid for payment
- change the font size in tag cloud
相关文章
- wordpress新增页面如何个性化设置
- select query in wordpress
- Get WooCommerce featured products in a WP_Query
- Woocommerce update shipping methods in checkout vi
- Change order status just after payment in WooComme
- Publishing or uploading failed. Error message: “Th
- Facebook Login With WP JWT Auth
- Wordpress development process
I came across this answer and was able to implement for a production site. This answer is related to woocommerce error codes notices. You need to find the codes in the separate class files (~woocommerce/includes/). For my purpose the code was in ~woocommerce/includes/class-wc-coupon.php
Thanks to this page: http://wpquestions.com/WooCommerce_Remove_Coupon_code_already_applied_error_message/10598
The filters mentioned here work fine for editing the message itself, but if you want to edit the actual HTML markup containing the notice message, then you need to use the notice templates under
templates > notices
.There are three different files here, each for the different kinds of notices. In my case, I wanted to add a class to the coupon applied successfully notice, so I copied
success.php
over into my theme file. My code then looked like below:I did it for
error.php
file. file path iswoocommerce/templates/notices/error.php
Many of them are directly in the plugin files - unfortunately. Some messages are tied to filter hooks that allow you to edit them without messing with plugin files but that's not always the case.
The message you wanted to change was "Product Name was successfully added to your cart". This one is set in the function wc_add_to_cart_message in wc-cart-functions.php and this function allows you to change it using a filter:
So in your functions.php file you could add something like:
Open the plugin files and search for
wc_add_notice
:This function has a filter:
The
$notice_type
is the second argument passed in all those occurrences.Using something like this should work: