在尝试编程中创建新订单的WooCommerce中,状态是付款

发布于 2025-01-22 05:07:45 字数 1820 浏览 0 评论 0原文

我在编程中最艰难的时间在WooCommerce中创建订单。 我们的网站上有一个表格,希望用户填写表格并提交,并使用他在表格中提交的用户详细信息创建订单。在这里,您可以看到 https://www.fitnessoneoneformulas.com/select-formulas.com/select-a a -fre-froduct/

现在有两个问题问题,

  1. 我们的产品以我们的形式 ,他可以选择该产品,但我们可以' t配置我们如何调用所选产品的 ID
  2. 我们必须在代码中添加默认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

  1. 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.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个ˇ局外人 2025-01-29 05:07:45
$order->update_status("completed", 'Imported order', TRUE); 

订单状态应在较低的情况下,例如完成 on-hold处理 待处理取消代码>,<代码>退还,失败

$order->update_status("completed", 'Imported order', TRUE); 

Order status should be in lower case like completed on-hold, processing pending, cancelled, refunded, failed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文