在以编程方式创建订单时,不会调用Woocommerce webhook

时间:2015-10-07 20:26:28

标签: wordpress woocommerce

我已使用此代码创建了订单。在后端的订单部分成功创建订单,但不调用webhook。

$address = array(
            'first_name' => 'Fresher',
            'last_name'  => 'StAcK OvErFloW',
            'company'    => 'stackoverflow',
            'email'      => 'test@test.com',
            'phone'      => '777-777-777-777',
            'address_1'  => '31 Main Street',
            'address_2'  => '', 
            'city'       => 'Chennai',
            'state'      => 'TN',
            'postcode'   => '12345',
            'country'    => 'IN'
        );

        $order = wc_create_order();
        $order->add_product( get_product( '12' ), 2 ); //(get_product with id and next is for quantity)
        $order->set_address( $address, 'billing' );
        $order->set_address( $address, 'shipping' );
        $order->calculate_totals();

当我通常创建订单时,交付URL已成功ping通,我也可以在日志中看到它。

知道如何调用webhook吗?

1 个答案:

答案 0 :(得分:0)

您可以使用do_action()手动触发挂钩:

do_action( 'some_wc_hook' );