• I have set up a shipping calculator to only require a Country to be entered for the cost estimate. The Street, Town, State and Postcode/ZIP fields have been removed. The website is based in Australia.

    This works fine, however on the Shopping Cart page where the shipping location appears beneath the Cart Totals, sometimes a residue Asuatralian State location appears, even when the Country is set to somewhere else.

    How can I set the Address formatting variable so that it only contains Country information (at least until the full address is entered at the Checkout)?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi

    This code may help you:

    add_filter( 'woocommerce_formatted_address_replacements', function( $replacements, $args ){
        $replacements['{state}'] = ''; // or unset ( $replacements['{state}'] );
        return $replacements;
    }, 10, 2 );

    Good luck

    Thread Starter mudwort

    (@mudwort)

    Thanks for that.

    Just to check, is the
    // or unset ( $replacements['{state}'] );
    part of the whole code snippet or an alternative to
    $replacements['{state}'] = '';?

    • This reply was modified 4 years, 11 months ago by mudwort.
    • This reply was modified 4 years, 11 months ago by mudwort.

    You’re welcome.

    I’m not sure unset ( $replacements['{state}'] ); works.

    At first try:

    add_filter( 'woocommerce_formatted_address_replacements', function( $replacements, $args ){
        $replacements['{state}'] = '';
        return $replacements;
    }, 10, 2 );
    Thread Starter mudwort

    (@mudwort)

    Work perfectly. Thank you!

    Hi

    Well done!

    You’re welcome

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Address formatting query’ is closed to new replies.