使用woocommerce创建自定义帖子类型和项目

时间:2018-06-12 03:32:09

标签: woocommerce

我有一个电子商务解决方案,处理项目和订单..

我现在需要创建一个订单(不同于常规订购),这是自定义的,所以我想将post_type保存为" step-2"不是shop_order ......

我该如何改变?

这是我的常规create_order代码

function ttm11_store_customer_empty_box_delivery()
    {
        $products = $_POST['products'];
        $pickup_date = $_POST['pickupDate'];
        $shipping_address = $_POST['shippingAddress'];
        $billing_address = $_POST['billingAddress'];
        global $woocommerce;
        $args = array(
            'customer_id' => get_current_user_id(),
        );
        $order = wc_create_order($args);
        foreach ($products as $product) {
            $order->add_product(get_product($product['id']), $product['quantity']);
        }
        $order->set_address($shipping_address, 'shipping');
        $order->set_address($billing_address, 'billing');
        $order->calculate_totals();
        add_post_meta($order->id, 'ttm11_store_customer_empty_box_delivery_date', $pickup_date);
        add_post_meta($order->id, 'ttm11_notify_employee', true);
        update_post_meta($order->id, '_payment_method', 'ideal');
        update_post_meta($order->id, '_payment_method_title', 'iDeal');

        // Store Order ID in session so it can be re-used after payment failure
        WC()->session->order_awaiting_payment = $order->id;
        $redirect = '';
        $available_gateways = WC()->payment_gateways->get_available_payment_gateways();

        $result = $available_gateways['stripe_ideal']->process_payment($order->id);
        if ($result['result'] == 'success') {
            $result = apply_filters('woocommerce_payment_successful_result', $result, $order->id);
            $redirect = $result['redirect'];
        }

        wp_send_json(array("success" => true, "redirect" => $redirect, "result" => $result));
    }

由于

0 个答案:

没有答案