• Resolved businesscloudinc

    (@businesscloudinc)


    Hello, thank you for this great plugin! I am hoping you could help me with a challenge I am facing.

    I have added the code below to move the custom fields within the billing address details. However, when I test, the fields show both above the billing address as well as within the billing details. Is there a way to only show them within the billing details on both the checkout page and emails? Here are screenshots of the issue:
    https://drive.google.com/file/d/1iB7i-t7bxr1K_4Z–HS04v5-7u0aYdhT/view?usp=sharing
    https://drive.google.com/file/d/1uO2cBn6Ido3_TXbnQUhqxYcZ5Wz18zF_/view?usp=sharing

    //Order Billing Fields
    add_filter( 'woocommerce_order_formatted_billing_address' , 'th56t_woo_custom_order_formatted_billing_address', 10, 2 );
    function th56t_woo_custom_order_formatted_billing_address( $address, $WC_Order ) {
         
         $address['billing_title'] = get_post_meta( $WC_Order->get_id(), 'billing_title', true );
    	 $address['additional_sector'] = get_post_meta( $WC_Order->get_id(), 'additional_sector', true );
    	 $address['additional_other'] = get_post_meta( $WC_Order->get_id(), 'additional_other', true );
    
        return $address;
    
    }
    
    add_filter( 'woocommerce_formatted_address_replacements', function( $replacements, $args ){
    	$replacements['{billing_title}'] = isset($args['billing_title']) ? $args['billing_title'] : '';
    	$replacements['{additional_sector}'] = isset($args['additional_sector']) ? $args['additional_sector'] : '';
    	$replacements['{additional_other}'] = isset($args['additional_other']) ? $args['additional_other'] : '';
        return $replacements;
    
    }, 10, 2 );
    
    add_filter( 'woocommerce_localisation_address_formats' , 'woo_includes_address_formats', 10, 1);
    function woo_includes_address_formats($address_formats) {
    	
        $address_formats['default'] = "{company}\n{name}\n{billing_title}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}\n{additional_sector}{additional_other}"; // default address format
    	// Add your country address format here
    	
        return $address_formats;
    
    }

    Also, is there a way I could add labels before each billing fields? I.e. it would say
    Company: {company}
    Name: {name}
    Title: {billing_title}
    etc.

    Thank you in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter businesscloudinc

    (@businesscloudinc)

    I figured it out. I had to uncheck the “Display in Emails” and “Display in Order Detail Pages” and the duplication was gone. For some reason tho, when I make a change in functions.php the code stops working until I modify it slightly and save again.

    I also figured out the labels thing.

    Plugin Author ThemeHigh

    (@themehigh)

    Great!

    Thread Starter businesscloudinc

    (@businesscloudinc)

    Would you know why or have you run into an issue where the code in functions.php wouldn’t always execute? I noticed during my testing that it sometimes works (with free orders) and shows the modified address format but sometimes it reverts back to the default (paid orders).

    Thread Starter businesscloudinc

    (@businesscloudinc)

    Nevermind, I fixed that as well! Including the solution, if somebody else is having this issue – I had to add another line for the $address_formats so I have $address_formats[‘default’] and $address_formats[‘CA’] to make it work for both paid and free orders.

    Plugin Author ThemeHigh

    (@themehigh)

    Thank you for letting us know ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Fields location’ is closed to new replies.