Skip to content

Instantly share code, notes, and snippets.

@dianewallace
Last active November 17, 2020 17:42
Show Gist options
  • Save dianewallace/67b85307fa632bff0f732cce968a9cd4 to your computer and use it in GitHub Desktop.
Save dianewallace/67b85307fa632bff0f732cce968a9cd4 to your computer and use it in GitHub Desktop.
Update the Woocommerce No Shipping message to include contact details.
add_filter( 'woocommerce_cart_no_shipping_available_html', 'myplugin_no_shipping_available_message' );
add_filter( 'woocommerce_no_shipping_available_html', 'myplugin_no_shipping_available_message' );
/**
* Update the Woocommerce No Shipping message to include contact details.
*/
function myplugin_no_shipping_available_message( $message ) {
$country = WC()->customer->get_shipping_country();
$mailto = 'mailto:' . get_option( 'admin_email' ); // Could also be 'woocommerce_stock_email_recipient'.
$link = sprintf( wp_kses( __( '<a href="%s">contact us</a>', 'my-plugin' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $mailto ) );
if ( ! empty( $country ) ) {
$all_countries = WC()->countries->get_countries();
return sprintf( 'Please %1$s for shipping rates to %2$s.', $link, $all_countries[ $country ] );
}
return sprintf( 'Sorry, no shipping options were found. Please %s for shipping rates', $link );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment