Last active
January 16, 2019 06:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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