Forked from lucasstark/gravity-forms-product-addons-custom-export-fields.php
Created
April 28, 2019 18:26
-
-
Save cconversion/49706f3dfdfad100080c979a41de3bd9 to your computer and use it in GitHub Desktop.
Custom export fields for WooCommerce Gravity Forms Product Addons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'gform_export_fields', 'custom_add_wc_order_fields', 10, 1 ); | |
add_filter( 'gform_export_field_value', 'custom_export_wc_order_fields', 10, 4 ); | |
function custom_add_wc_order_fields( $form ) { | |
array_push( $form['fields'], array( | |
'id' => 'woocommerce_billing_address_1', | |
'label' => __( 'WooCommerce Billing Address 1', 'wc_gf_addons' ) | |
) ); | |
array_push( $form['fields'], array( | |
'id' => 'woocommerce_billing_address_2', | |
'label' => __( 'WooCommerce Billing Address 2', 'wc_gf_addons' ) | |
) ); | |
//Add any additional fields you need included in the export. | |
} | |
function custom_export_wc_order_fields( $value, $form_id, $field_id, $entry ) { | |
switch ( $field_id ) { | |
case 'woocommerce_billing_address_1' : | |
$order_id = gform_get_meta( $entry['id'], 'woocommerce_order_number' ); | |
if ( $order_id ) { | |
$order = wc_get_order( $order_id ); | |
if ( $order ) { | |
$value = $order->get_billing_address_1(); | |
} | |
} | |
break; | |
case 'woocommerce_billing_address_2' : | |
$order_id = gform_get_meta( $entry['id'], 'woocommerce_order_number' ); | |
if ( $order_id ) { | |
$order = wc_get_order( $order_id ); | |
if ( $order ) { | |
$value = $order->get_billing_address_2(); | |
} | |
} | |
break; | |
} | |
/* | |
Add any additional fields you need included in the export. | |
See https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html for details on what functions are available to retrieve order information. | |
*/ | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment