WooCommerce: How to insert a value from $_GET into $order->update_meta_data
-
I’m trying to insert a value as custom meta for a WooCommerce order from a query string parameter the url e.g.: mystore.com/checkout?myparam=customvalue
For some reason I cannot return any value from
$_GET
:add_action('woocommerce_checkout_create_order', 'before_checkout_create_order', 20, 2); function before_checkout_create_order( $order, $data ) { if ( isset( $_GET['myparam'] ) ) { $myvalue = $_GET['myparam']; } $order->update_meta_data( '_mymeta', $myvalue ); }
I’m confused because I believe
woocommerce_checkout_create_order
fires upon hitting submit for the checkout so I don’t understand why it wouldn’t be able to pull this from the current url.I’ve tested dummy values such as
$myvalue = 'test';
to ensure the meta data is inserted and that works fine.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘WooCommerce: How to insert a value from $_GET into $order->update_meta_data’ is closed to new replies.