parent
d1f9cbfcf2
commit
ca29deead9
|
@ -150,7 +150,17 @@ class WC_Checkout {
|
|||
}
|
||||
|
||||
/**
|
||||
* create_order function.
|
||||
* Create an order.
|
||||
*
|
||||
* Error codes:
|
||||
* 400 - Cannot insert order into the database
|
||||
* 401 - Cannote update existing order
|
||||
* 402 - Cannot create line item
|
||||
* 403 - Cannot create fee item
|
||||
* 404 - Cannot create shipping item
|
||||
* 405 - Cannot create tax item
|
||||
* 406 - Cannot create coupon item
|
||||
*
|
||||
* @access public
|
||||
* @throws Exception
|
||||
* @return int|WP_ERROR
|
||||
|
@ -183,7 +193,7 @@ class WC_Checkout {
|
|||
$order = wc_update_order( $order_data );
|
||||
|
||||
if ( is_wp_error( $order ) ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 401 ) );
|
||||
} else {
|
||||
$order->remove_order_items();
|
||||
do_action( 'woocommerce_resume_order', $order_id );
|
||||
|
@ -194,7 +204,7 @@ class WC_Checkout {
|
|||
$order = wc_create_order( $order_data );
|
||||
|
||||
if ( is_wp_error( $order ) ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 400 ) );
|
||||
} else {
|
||||
$order_id = $order->id;
|
||||
do_action( 'woocommerce_new_order', $order_id );
|
||||
|
@ -219,7 +229,7 @@ class WC_Checkout {
|
|||
);
|
||||
|
||||
if ( ! $item_id ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 402 ) );
|
||||
}
|
||||
|
||||
// Allow plugins to add order item meta
|
||||
|
@ -231,7 +241,7 @@ class WC_Checkout {
|
|||
$item_id = $order->add_fee( $fee );
|
||||
|
||||
if ( ! $item_id ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 403 ) );
|
||||
}
|
||||
|
||||
// Allow plugins to add order item meta to fees
|
||||
|
@ -244,7 +254,7 @@ class WC_Checkout {
|
|||
$item_id = $order->add_shipping( $package['rates'][ $this->shipping_methods[ $package_key ] ] );
|
||||
|
||||
if ( ! $item_id ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 404 ) );
|
||||
}
|
||||
|
||||
// Allows plugins to add order item meta to shipping
|
||||
|
@ -255,14 +265,14 @@ class WC_Checkout {
|
|||
// Store tax rows
|
||||
foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
|
||||
if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 405 ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Store coupons
|
||||
foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
|
||||
if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 406 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue