在尝试编程中创建新订单的WooCommerce中,状态是付款
我在编程中最艰难的时间在WooCommerce中创建订单。 我们的网站上有一个表格,希望用户填写表格并提交,并使用他在表格中提交的用户详细信息创建订单。在这里,您可以看到 https://www.fitnessoneoneformulas.com/select-formulas.com/select-a a -fre-froduct/
我现在有两个问题问题,
- 我们的产品以我们的形式 ,他可以选择该产品,但我们可以' t配置我们如何调用所选产品的 ID 。
- 我们必须在代码中添加默认ID才能检查是否创建订单?而且它运行得非常顺利并创建订单,但他们向我展示了订单的状态是付款。
注意:所有产品的价格为零。
这是我们用来创建订单的代码,
add_action( 'wpcf7_before_send_mail', 'CF7_pre_send' );
function CF7_pre_send($cf7) {
global $woocommerce;
global $product;
$address = array(
"first_name" => $_POST["firstname"],
"last_name" => $_POST["LastName"],
"product" => $_POST["products-54"],
"country" => $_POST["country_auto-565"],
"state" => $_POST["state_auto-625"],
"city" => $_POST["city_auto-896"],
"postcode" => $_POST["number-594"],
"address_1" => $_POST["Address"],
"address_2" => $_POST["Address"],
"phone" => $_POST["phonetext-523"],
"email" => $_POST["email-557"]
);
file_put_contents("new_array.txt", $address);
// Now we create the order
$order = wc_create_order();
// The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
$order->add_product( wc_get_product( '20604'), 1); // This is an existing SIMPLE product
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
//
$order->calculate_totals();
$order->update_status("Completed", 'Imported order', TRUE);
}
仅订单将在免费产品上创建或价格为零 对此的任何帮助将不胜感激!
I am having the hardest time programmatically creating orders in WooCommerce.
We have a form on our website that wants the user to fill the form and submit it and create the order using the user details that he submitted in the form. here you can see the form https://www.fitnessoneformulas.com/select-a-free-product/
I have two just problems right now
- we have a dropdown of the products in our form there he can select the product but we can't configure how we can call the id of the selected product.
- We have to add the default id in our code to check if it's creating the order or not? and it's working very smoothly and creating the order but they show me the status of the order is payment pending.
NOTE: The price of all the products is Zero.
Here is the code that we have used to create the order
add_action( 'wpcf7_before_send_mail', 'CF7_pre_send' );
function CF7_pre_send($cf7) {
global $woocommerce;
global $product;
$address = array(
"first_name" => $_POST["firstname"],
"last_name" => $_POST["LastName"],
"product" => $_POST["products-54"],
"country" => $_POST["country_auto-565"],
"state" => $_POST["state_auto-625"],
"city" => $_POST["city_auto-896"],
"postcode" => $_POST["number-594"],
"address_1" => $_POST["Address"],
"address_2" => $_POST["Address"],
"phone" => $_POST["phonetext-523"],
"email" => $_POST["email-557"]
);
file_put_contents("new_array.txt", $address);
// Now we create the order
$order = wc_create_order();
// The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
$order->add_product( wc_get_product( '20604'), 1); // This is an existing SIMPLE product
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
//
$order->calculate_totals();
$order->update_status("Completed", 'Imported order', TRUE);
}
Only the order will create on the free product or the price is zero
Any help on this would be MOST appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
订单状态应在较低的情况下,例如
完成
on-hold
,处理
待处理
,取消
代码>,<代码>退还,失败
Order status should be in lower case like
completed
on-hold
,processing
pending
,cancelled
,refunded
,failed