• Resolved KoolPal

    (@koolpal)


    Using Woocommerce 3.2.3

    Currently the checkout error message shows the country code

    Unfortunately we do not ship to UA. Please enter an alternative shipping address.

    This looks ugly and incomplete.

    What code snippet can be used to show the full country name Ukraine?

    I have been experimenting with the code snippet provided by @eljkmw here Link to code snippet on this forum but it does seem to be working even on a vanilla Woocommerce installation with Boutique child theme.

    I have created a new thread since @eljkmw’s thread was marked as resolved by him and new posts do not move the thread in this forum.

    Some assistance would be appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • @koolpal :: Please check my latest reply.

    Thread Starter KoolPal

    (@koolpal)

    Awesome @eljkmw! Your revised changes worked since I am using the standard error messages!

    I am copying the complete code here in case anybody else would need it!

    // Convert error message of ISO 2 country code into country name
    function wc_error_convert_country_code( $message ) {
    	$line1 = 'Unfortunately <strong>we do not ship to ';			// first half of the message
    	$line2 = '</strong>. Please enter an alternative shipping address.';	// second half of the message
    
    	// find $line1 sub-string in $message string
    	$pos = strpos( $message, $line1 );	// get position of sub-string
    	if ( $pos !== false ) {
    		// Does $line1 has ' the' append to it ?
    		if ( strpos( $message, ' the', $pos ) !== false ) {
    			$country_code2 = substr( $message, strlen( $line1 )+4, 2 );	// reads ISO 2 country code
    			$country_name = WC()->countries->countries[ $country_code2 ];	// converts to full country name
    			$message = $line1 . ' the ' . $country_name . $line2;
    		} else {
    			$country_code2 = substr( $message, strlen( $line1 ), 2 );	// reads ISO 2 country code
    			$country_name = WC()->countries->countries[ $country_code2 ];	// converts to full country name
    			$message = $line1 . $country_name . $line2;				
    		}
    	}
    	return $message;
    }
    add_filter( 'woocommerce_add_error', 'wc_error_convert_country_code' );

    God bless you @eljkmw!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show full country name in Checkout error’ is closed to new replies.