Created
August 16, 2016 14:15
-
-
Save WooForce/dac75bd0a03b48624d458432ac767eae to your computer and use it in GitHub Desktop.
Alter messages for incomplete address in shipping caluculator
This file contains hidden or 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
add_filter( 'woocommerce_cart_no_shipping_available_html', 'wf_custom_message_for_incomplete_address', 10, 1 ); // Alters message on Cart page | |
add_filter( 'woocommerce_no_shipping_available_html', 'wf_custom_message_for_incomplete_address', 10, 1 ); // Alters message on Checkout page | |
function wf_custom_message_for_incomplete_address( $default ) { | |
$wf_cart_country = WC()->customer->get_shipping_country(); | |
$wf_cart_state = WC()->customer->get_shipping_state(); | |
$wf_cart_postcode = WC()->customer->get_shipping_postcode(); | |
$shipping_msg_array = array(); | |
empty($wf_cart_country) ? $shipping_msg_array[] = 'Country' : ''; | |
empty($wf_cart_state) ? $shipping_msg_array[] = 'State' : ''; | |
empty($wf_cart_postcode) ? $shipping_msg_array[] = 'Postcode' : ''; | |
if( !empty( $shipping_msg_array ) ){ | |
if( count($shipping_msg_array) > 1 ){ | |
$shipping_msg = implode(", ", $shipping_msg_array); | |
return $shipping_msg . " are empty.Please fill up those fields"; | |
}else{ | |
$shipping_msg = $shipping_msg_array[0]; | |
return $shipping_msg . " is empty.Please fill up the field"; | |
} | |
} | |
else | |
return $default; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment