Skip to content

Commit 4e263be

Browse files
matty0501spivurno
andauthored
gspc-add-entry-data-to-woo-order-custom-field.php: Added new snippet. (#894)
* `gspc-add-entry-data-to-woo-order-custom-field.php`: Added new snippet. * `gspc-add-entry-data-to-woo-order-custom-field.php`: Fixed PHPCS issues. --------- Co-authored-by: David Smith <[email protected]>
1 parent 81df57d commit 4e263be

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Gravity Shop // GS Product Configurator // Add Entry Data to WooCommerce Order Custom Field
4+
* https://gravitywiz.com/documentation/gravity-shop-product-configurator/
5+
*
6+
* Add data from the Gravity Forms entry attached to a cart item to a custom field on the WooCommerce order when the order is created.
7+
* This is useful for integrations such as ShipStation, which expect custom data to be attached to the order as a custom field.
8+
*
9+
* Instructions:
10+
* 1. Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
11+
* 2. Configure the snippet based on inline instructions.
12+
*/
13+
add_action( 'woocommerce_checkout_create_order_line_item', function ( $item, $cart_item_key, $values, $order ) {
14+
15+
$entry_ids = $item->get_meta( 'gspc_gf_entry_ids', true );
16+
17+
if ( $entry_ids ) {
18+
19+
$entry_id = $entry_ids[0];
20+
21+
$entry = GFAPI::get_entry( $entry_id );
22+
23+
$data = rgar( $entry, '4' ); // Replace 4 with the field ID you need
24+
25+
$order->update_meta_data( '_my_custom_key', $data ); // Replace _my_custom_key with your custom meta key
26+
27+
}
28+
29+
}, 10, 4 );

0 commit comments

Comments
 (0)