Skip to content

Instantly share code, notes, and snippets.

@tiendungdev
Created September 25, 2022 06:52
Show Gist options
  • Select an option

  • Save tiendungdev/81712c32b8714f40f1f381f9329be1d6 to your computer and use it in GitHub Desktop.

Select an option

Save tiendungdev/81712c32b8714f40f1f381f9329be1d6 to your computer and use it in GitHub Desktop.

Revisions

  1. tiendungdev created this gist Sep 25, 2022.
    30 changes: 30 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    add_action('woocommerce_checkout_process', 'create_vip_order');

    function create_vip_order() {

    global $woocommerce;

    $address = array(
    'first_name' => 'Tien Dung',
    'last_name' => 'Dao',
    'company' => 'TTV',
    'email' => [email protected]',
    'phone' => '0354548599',
    'address_1' => 'Bui Quang La - Go Va.',
    'address_2' => '',
    'city' => 'HCMC',
    'state' => '',
    'postcode' => '700000',
    'country' => ''
    );

    // 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( get_product('275962'), 1); // This is an existing SIMPLE product
    $order->set_address( $address, 'billing' );
    //
    $order->calculate_totals();
    $order->update_status("Completed", 'Imported order', TRUE);
    }