Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add content and notices to the WooCommerce checkout - sample code
/**
* Each of these samples can be used - note that you should pick one rather than add them all.
*
* How to use WC notices: https://github.com/woothemes/woocommerce/blob/master/includes/wc-notice-functions.php#L96
* Tutorial: http://www.skyverge.com/blog/edit-woocommerce-templates/
**/
/**
* Add a content block after all notices, such as the login and coupon notices.
*
* Reference: https://github.com/woothemes/woocommerce/blob/master/templates/checkout/form-checkout.php
*/
add_action( 'woocommerce_before_checkout_form', 'skyverge_add_checkout_content', 12 );
function skyverge_add_checkout_content() {
echo 'This content that you can use to tell customers stuff. You could make it a div class="checkout-message" and style it if you wanted.';
}
/**
* Add a content in a notice instead. Let's add it before other notices with a priority = 9
*
* Reference: https://github.com/woothemes/woocommerce/blob/master/templates/checkout/form-checkout.php
*/
add_action( 'woocommerce_before_checkout_form', 'skyverge_add_checkout_success', 9 );
function skyverge_add_checkout_success() {
wc_print_notice( __( 'A success message with high priority.', 'woocommerce' ), 'success' );
}
/**
* Add an info notice instead. Let's add it after other notices with priority = 11
*
* Reference: https://github.com/woothemes/woocommerce/blob/master/templates/checkout/form-checkout.php
*/
add_action( 'woocommerce_before_checkout_form', 'skyverge_add_checkout_notice', 11 );
function skyverge_add_checkout_notice() {
wc_print_notice( __( 'A notice message instead.', 'woocommerce' ), 'notice' );
}
/**
* Add add a notice before the payment form - let's use an eror notice. Could also use content, etc.
*
* Reference: https://github.com/woothemes/woocommerce/blob/master/templates/checkout/review-order.php
*/
add_action( 'woocommerce_review_order_before_payment', 'skyverge_before_paying_notice' );
function skyverge_before_paying_notice() {
wc_print_notice( __( 'An error message.', 'woocommerce' ), 'error' );
}
@crisweiser

This comment has been minimized.

crisweiser commented Apr 9, 2015

Nice piece of code. Thank you.

@jnz31

This comment has been minimized.

jnz31 commented Aug 24, 2015

very helpful. thanks.

@kulcsart

This comment has been minimized.

kulcsart commented May 12, 2016

Great collection, thank you for share!

@tjtommy

This comment has been minimized.

tjtommy commented Dec 17, 2016

How can i put the username of the costumer in the notice?

@dennishelbig

This comment has been minimized.

dennishelbig commented Apr 3, 2017

highly appreciated, thank you.

@sHaRmamAmTa

This comment has been minimized.

sHaRmamAmTa commented Jul 4, 2017

how to add transitions of the notices, so that they fade out after some time!!

@ryanshoover

This comment has been minimized.

ryanshoover commented Jul 9, 2017

Great collection covering the options. Many thanks!

@warunanc

This comment has been minimized.

warunanc commented Sep 26, 2017

Thanks for these snippets. With the help from following link - anything is possible in Checkout page
WooCommerce Visual Hook Guide: Checkout Page
https://businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/

@indefinitelee

This comment has been minimized.

indefinitelee commented Oct 19, 2017

thanks for this. I want to change the success/failure notice for applying a coupon on my cart page.

would this code in my child theme overwrite the default notice text?

@dogrescuer

This comment has been minimized.

dogrescuer commented Apr 30, 2018

Thank you for this code. Does the woocommerce_review_order_before_payment example mean to imply that one will not see error messages unless placed as described?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment