Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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