updating woocommerce order in checkout page instead to create a new one

前端 未结 3 1765
野的像风
野的像风 2021-01-16 06:23

I am creating a Wordpress and WooCommerce plugin which does the following:

  1. An anonymous user customizes a product on the page
  2. In a php script in the
3条回答
  •  失恋的感觉
    2021-01-16 06:55

    You can use the function wc_update_order() to fetch an existing order object.

    $order_id = $_GET[ 'order_id' ]
    $order = wc_update_order( array ( 'order_id' => $order_id ) );
    
    // now you got the woocommerce order object and you can execute many functions
    //
    $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->add_product( get_product( '12' ), 1 ); //(get_product with id and next is for quantity)
    $order->set_address( $address, 'billing' );
    $order->set_address( $address, 'shipping' );
    $order->calculate_totals();
    

    For a complete list of all the functions you can call on the order object, execute the following code after you fetch your order

    var_dump( get_class_methods( $order ) );
    

    This will list all the functions that are available to the Woocommerce Order object.

    Hope this answers your question

提交回复
热议问题