简体   繁体   English

Woocommerce 添加本地取货信息以编程方式订购

[英]Woocommerce add Local pickup information to order programmatically

I am creating an order with php.我正在用 php 创建一个订单。 I have successfully created the order, however, cannot add local picup information.我已经成功创建订单,但是无法添加本地取件信息。

I am using WooCommerce Local Pickup Plus plugin.我正在使用 WooCommerce Local Pickup Plus 插件。

I want to add below fields to the order:我想在订单中添加以下字段:

  1. Shipping method: Local pickup (already added to woocommerce)送货方式:本地取货(已添加到woocommerce)
  2. Pickup location: North Miami Beach (already added to woocommerce)取货地点:北迈阿密海滩(已加入woocommerce)
  3. Pickup Date (user selected)取件日期(用户选择)
  4. Items to Pickup (all items in cart)要取的物品(购物车中的所有物品)

My code till now:我的代码到现在:

<?php
$woocommerce->cart->empty_cart();
$product_id=358;
$quantity=3;
$variationID=766;
$attr_array=array(
    'choose-a-flavor' => 'Red Velvet'
);
$address = array(
    'first_name' => 'Arka',
    'last_name'  => 'Debnath',
    'company'    => 'Arkas',
    'email'      => 'my.email@mail.com',
    'phone'      => '123-456-780',
    'address_1'  => '123 Main st.',
    'address_2'  => '104',
    'city'       => 'San Diego',
    'state'      => 'Ca',
    'postcode'   => '92121',
    'country'    => 'US'
);
$woocommerce->cart->add_to_cart($product_id, $quantity, $variationID, $attr_array);

$order_data = array(
     'status' => apply_filters('woocommerce_default_order_status', 'processing')
);
$new_order = wc_create_order($order_data);
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
        $item_id = $new_order->add_product(
            $values['data'], $values['quantity'], array(
            'variation' => $values['variation'],
            'totals' => array(
                'subtotal' => $values['line_subtotal'],
                'subtotal_tax' => $values['line_subtotal_tax'],
                'total' => $values['line_total'],
                'tax' => $values['line_tax'],
                'tax_data' => $values['line_tax_data']
            )
            )
        );
    }
$new_order->set_address($address, 'billing');
$new_order->set_address($address, 'shipping');
$new_order->calculate_totals();

// The below part does not work

$woocommerce->shipping->load_shipping_methods();
$shipping_methods = $woocommerce->shipping->get_shipping_methods();
$selected_shipping_method = $shipping_methods['local_pickup'];
$shippingMethod = new \WC_Shipping_Rate($selected_shipping_method->id,$selected_shipping_method->title, 0);
$new_order->add_shipping($shippingMethod);

?>

OK no help sp far.确定没有帮助 sp 远。 I didn't find and wordpress hook anywhere to do this safely.我没有在任何地方找到和 wordpress 挂钩来安全地做到这一点。 So I went the bad way this time.所以这次我走的不好。 Added line items in the database directly.直接在数据库中添加了行项目。

INSERT INTO `wp_woocommerce_order_items` (`order_item_id`, `order_item_name`, `order_item_type`, `order_id`) values (null, 'Local Pickup', 'shipping', '$OrderID')

INSERT INTO `wp_woocommerce_order_itemmeta` (`meta_id`, `order_item_id`, `meta_key`, `meta_value`) VALUES
(null, $OrdeItemID, 'method_id', 'local_pickup_plus'),
(null, $OrdeItemID, 'instance_id', '0'),
(null, $OrdeItemID, 'cost', '0.00'),
(null, $OrdeItemID, 'total_tax', '0'),
(null, $OrdeItemID, 'taxes', 'a:1:{s:5:\"total\";a:0:{}}'),
(null, $OrdeItemID, '_pickup_location_id', '$PickupPostal'),
(null, $OrdeItemID, '_pickup_location_name', 'PickupName'),
(null, $OrdeItemID, '_pickup_location_address', '$PickupLocationArray'),
(null, $OrdeItemID, '_pickup_location_phone', ''),
(null, $OrdeItemID, '_pickup_date', '$DateOfPickup'),
(null, $OrdeItemID, '_pickup_minimum_hours', '$PickupTimeMin'),
(null, $OrdeItemID, '_pickup_items', '$Pickupitem')

I know this is not good, but I don't have a better choice yet.我知道这不好,但我还没有更好的选择。 If someone has a solution I will be happy to implement.如果有人有解决方案,我将很乐意实施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将电子邮件收件人添加到 Woocommerce 中本地取货的新订单通知 - Add email recipients to New order notification for Local pickup in Woocommerce 如何将“本地取件加取件日期”添加到 WooCommerce 管理订单列表中的新列 - How to add "Local Pickup Plus pickup date" to a new column in WooCommerce admin order list 从 Woocommerce 的订单中获取本地取货和详细信息 - Get Local pickup plus details from the order in Woocommerce 如果运输方式是本地取货,请在 Woocommerce 中填写订单备注 - Make Order notes required if shipping method is local pickup in Woocommerce 向特定的电子邮件通知中添加自定义文本,以接收本地取货Woocommerce订单 - Add a custom text to specific email notification for local pickup Woocommerce orders 添加 COD 费用,除非在 WooCommerce 结账时选择本地取货 - Add fee for COD, unless local pickup is chosen on WooCommerce checkout 在Woocommerce 3中以编程方式向订单添加送货 - Add a shipping to an order programmatically in Woocommerce 3 在 Woocommerce 3 中以编程方式向订单添加费用 - Add a fee to an order programmatically in Woocommerce 3 我想在wp-woocommerce中停止本地提货的订单完整通知 - I want to stop order complete notification for local-pickup in wp-woocommerce Woocommerce本地取货加php取货日期时间 - Woocommerce local pickup plus php pickup date and time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM