Populate Country from WooCommerce into Gravity Forms Address field

Experimental Snippet 🧪

Code

Filename: gppa-wc-country-to-gf-address-field.php

<?php
/**
 * Gravity Perks // Populate Anything // Populate Country from WooCommerce into Gravity Forms Address field
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * Experimental Snippet 🧪
 */
// Update "26" to your Address field ID. Leave the ".6" alone.
add_filter( 'gppa_process_template_26.6', function( $template_value, $field, $template_name, $populate, $object, $object_type, $objects, $template ) {
	if ( $template === 'meta_billing_country' ) {
		$countries      = GF_Fields::get( 'address' )->get_default_countries();
		$template_value = rgar( $countries, $template_value, $template_value );
	}
	return $template_value;
}, 10, 8 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.