admin管理员组文章数量:1122832
I am working on a code to create a woocommerce order manually from a gravity form submission.
I have 'custom notes' that I have managed to add to order notes BUT ideally it would be in a meta box below the product/item line.
Any suggestions would be appreciated (I am self taught and not expert).
Here is my code:
add_action( 'gform_after_submission_56', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
global $woocommerce;
// use this to find out $entry output
var_dump($entry);
// Make sure to add hidden field somewhere in the form with product id and define it here, If you have some other way of defining products in the form you need to make sure product id is returned in the variable below somehow
$user_id =rgar( $entry, '97' );
$note = rgar( $entry, '53' );
$product_id = rgar( $entry, '71' );
$quantity = rgar( $entry, '73' );
$address = array(
'first_name' => rgar( $entry, '98' ),
'last_name' => rgar( $entry, '99' ),
'company' => rgar( $entry, '' ),
'email' => rgar( $entry, '83' ),
'phone' => rgar( $entry, '84' ),
'address_1' => rgar( $entry, '88.1' ),
'address_2' => rgar( $entry, '88.2' ),
'city' => rgar( $entry, '88.3' ),
'state' => rgar( $entry, '88.4' ),
'postcode' => rgar( $entry, '88.5' ),
'country' => rgar( $entry, '88.6' ),
);
$order = wc_create_order();
$order->set_customer_id( $user_id );
$order->add_product( wc_get_product($product_id), $quantity, $prices);
$order->set_address( $address, 'billing' );
$order->calculate_totals();
$order->update_status("on hold", 'pending', TRUE);
$order->add_order_note( $note );
}
I am working on a code to create a woocommerce order manually from a gravity form submission.
I have 'custom notes' that I have managed to add to order notes BUT ideally it would be in a meta box below the product/item line.
Any suggestions would be appreciated (I am self taught and not expert).
Here is my code:
add_action( 'gform_after_submission_56', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
global $woocommerce;
// use this to find out $entry output
var_dump($entry);
// Make sure to add hidden field somewhere in the form with product id and define it here, If you have some other way of defining products in the form you need to make sure product id is returned in the variable below somehow
$user_id =rgar( $entry, '97' );
$note = rgar( $entry, '53' );
$product_id = rgar( $entry, '71' );
$quantity = rgar( $entry, '73' );
$address = array(
'first_name' => rgar( $entry, '98' ),
'last_name' => rgar( $entry, '99' ),
'company' => rgar( $entry, '' ),
'email' => rgar( $entry, '83' ),
'phone' => rgar( $entry, '84' ),
'address_1' => rgar( $entry, '88.1' ),
'address_2' => rgar( $entry, '88.2' ),
'city' => rgar( $entry, '88.3' ),
'state' => rgar( $entry, '88.4' ),
'postcode' => rgar( $entry, '88.5' ),
'country' => rgar( $entry, '88.6' ),
);
$order = wc_create_order();
$order->set_customer_id( $user_id );
$order->add_product( wc_get_product($product_id), $quantity, $prices);
$order->set_address( $address, 'billing' );
$order->calculate_totals();
$order->update_status("on hold", 'pending', TRUE);
$order->add_order_note( $note );
}
Share
Improve this question
edited Feb 22, 2020 at 10:38
7uc1f3r
2292 silver badges7 bronze badges
asked Feb 22, 2020 at 5:36
Jessica GronowJessica Gronow
171 bronze badge
2
- What are you having trouble with? It's not clear from your question. – Jacob Peattie Commented Feb 22, 2020 at 8:46
- Is it a part of WordPress? – Max Yudin Commented Feb 22, 2020 at 15:12
1 Answer
Reset to default 0I think you can use the following:
$order->update_meta_data( 'YOUR_META_KEY_HERE', $note );
Remember to replace YOUR_META_KEY_HERE with your preferred key, Complete code:
add_action( 'gform_after_submission_56', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
global $woocommerce;
// use this to find out $entry output
var_dump($entry);
// Make sure to add hidden field somewhere in the form with product id and define it here, If you have some other way of defining products in the form you need to make sure product id is returned in the variable below somehow
$user_id =rgar( $entry, '97' );
$note = rgar( $entry, '53' );
$product_id = rgar( $entry, '71' );
$quantity = rgar( $entry, '73' );
$address = array(
'first_name' => rgar( $entry, '98' ),
'last_name' => rgar( $entry, '99' ),
'company' => rgar( $entry, '' ),
'email' => rgar( $entry, '83' ),
'phone' => rgar( $entry, '84' ),
'address_1' => rgar( $entry, '88.1' ),
'address_2' => rgar( $entry, '88.2' ),
'city' => rgar( $entry, '88.3' ),
'state' => rgar( $entry, '88.4' ),
'postcode' => rgar( $entry, '88.5' ),
'country' => rgar( $entry, '88.6' ),
);
$order = wc_create_order();
$order->set_customer_id( $user_id );
$order->add_product( wc_get_product($product_id), $quantity, $prices);
$order->set_address( $address, 'billing' );
$order->calculate_totals();
$order->update_status("on hold", 'pending', TRUE);
$order->update_meta_data( 'YOUR_META_KEY_HERE', $note );
}
Thank You
本文标签: Manually create an order with a product ID woocommerce
版权声明:本文标题:Manually create an order with a product ID woocommerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286231a1927626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论