Created
September 25, 2022 06:52
-
-
Save tiendungdev/81712c32b8714f40f1f381f9329be1d6 to your computer and use it in GitHub Desktop.
Thêm đơn hàng bằng PHP - Woocommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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