Last active
June 24, 2020 13:23
-
-
Save robindevitt/8a092598137aac6c138c4d7a6d553e08 to your computer and use it in GitHub Desktop.
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
<?php | |
/* | |
* Create order dynamically | |
*/ | |
add_action( 'woocommerce_before_checkout_form', 'create_order' ); | |
function create_order() { | |
global $woocommerce; | |
$address = array( | |
'first_name' => 'Firstname', | |
'last_name' => 'Lastname', | |
'company' => 'Company', | |
'email' => '[email protected]', | |
'phone' => '012-345-6789', | |
'address_1' => 'Address line 1', | |
'address_2' => 'Address line 2', | |
'city' => 'City', | |
'state' => 'State', | |
'postcode' => '00000', | |
'country' => 'Country' | |
); | |
// Now we create the order | |
$order = wc_create_order(); | |
// Use the product IDs to add | |
$order->add_product( get_product( 123 ), 1); | |
// Set addresses | |
$order->set_address( $address, 'billing' ); | |
$order->set_address( $address, 'shipping' ); | |
// Set payment gateway | |
$payment_gateways = WC()->payment_gateways->payment_gateways(); | |
$order->set_payment_method( $payment_gateways['bacs'] ); | |
// Calculate totals | |
$order->calculate_totals(); | |
$order->update_status( 'Processing', 'Order created via Pick-A-Display - ', TRUE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment