Skip to content

Instantly share code, notes, and snippets.

@renjith-ph
Last active January 16, 2019 06:45
Show Gist options
  • Save renjith-ph/8f27c63d5a079d578ad3c7db00ece94b to your computer and use it in GitHub Desktop.
Save renjith-ph/8f27c63d5a079d578ad3c7db00ece94b to your computer and use it in GitHub Desktop.
Snippet to add custom message on top of checkout page if shipping methods are available.
/* Snippet to add custom message on top of checkout page if shipping methods are available.
Created at : 16 Jan 2019 PluginHive Plugins : https://www.pluginhive.com/plugins/
gist link: https://gist.github.com/renjith-ph/8f27c63d5a079d578ad3c7db00ece94b
*/
add_action( 'woocommerce_before_checkout_form', 'ph_add_custom_message_on_top_of_checkout_page_if_shipping_method_available', 10 );
function ph_add_custom_message_on_top_of_checkout_page_if_shipping_method_available()
{
$i=0;
$message="Do you qualify for a shipping discount? Give us a call at 541-419-6054"; // this message will display on top of checkout page
foreach (WC()->session->get('shipping_for_package_'.$i)['rates'] as $rate_index => $rates) {
if(!empty($rates))
{
wc_add_notice( __( $message, 'woocommerce' ), 'notice' ); // You can replace notice with error or success
break;
}
if(!isset(WC()->session->get('shipping_for_package_'.($i+1))['rates']))
{
break;
}
$i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment