Skip to content

Instantly share code, notes, and snippets.

@tiendungdev
Created September 25, 2022 06:52
Show Gist options
  • Save tiendungdev/81712c32b8714f40f1f381f9329be1d6 to your computer and use it in GitHub Desktop.
Save tiendungdev/81712c32b8714f40f1f381f9329be1d6 to your computer and use it in GitHub Desktop.
Thêm đơn hàng bằng PHP - Woocommerce
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment