Created
June 15, 2015 20:17
-
-
Save ameeker/746dbe2c46cd4d3978c3 to your computer and use it in GitHub Desktop.
Add WooCommerce Order ID column to Gravity Forms export
This file contains hidden or 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', 'add_fields', 10, 1 ); | |
function add_fields( $form ) { | |
array_push( $form['fields'], array( 'id' => 'orderid', 'label' => __( 'Order ID', 'gravityforms' ) ) ); | |
return $form; | |
} | |
add_filter( 'gform_export_field_value', 'set_export_values', 10, 4 ); | |
function set_export_values( $value, $form_id, $field_id, $lead ) { | |
switch( $field_id ) { | |
case 'orderid' : | |
$value = 'echo $order->id;'; | |
break; | |
} | |
return $value; | |
} |
Well, depending on how that extension works you may be able to get the order number by using the $form_id
. Something like this:
add_filter( 'gform_export_field_value', 'set_export_values', 10, 4 );
function set_export_values( $value, $form_id, $field_id, $lead ) {
$order = new WC_Order( $form_id );
if ( 'orderid' === $field_id && is_object( $order ) ) {
$value = $order->id;
}
return $value;
}
If that doesn't work, if the form is submitted on the product's page you can retrieve that from the $lead
parameter like this:
add_filter( 'gform_export_field_value', 'set_export_values', 10, 4 );
function set_export_values( $value, $form_id, $field_id, $lead ) {
$order = new WC_Order( url_to_postid( $lead['source_url'] ) );
if ( 'orderid' === $field_id && is_object( $order ) ) {
$value = $order->id;
}
return $value;
}
I think that's about the best I can do with the given information and my understanding of the plugins you're using. It might work... or not... 😀
The first example returns the form id; the second returns a 0.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Rob,
It's pulling from a Gravity Forms export. We are using the Gravity Forms product add on for Woo. The gravity forms export of the form includes all of the order information we need in a form we can use it, but it doesn't incclude the order ID