我正在使用此功能,此处定义:
http://woocommerce.wp-a2z.org/oik_api/wc_create_order/
但它给了我一个错误:
未捕捉错误:班级' WC_Order'在C:\ xampp \ htdocs \ wordpress \ wp-content \ plugins \ order.php中找不到:24
我甚至包含了wc-core-functions.php
文件。
include 'woocommerce/includes/wc-core-functions.php';
function wc_create( $args = array() ) {
$default_args = array(
'status' => null,
'customer_id' => null,
'customer_note' => null,
'parent' => null,
'created_via' => null,
'cart_hash' => null,
'order_id' => 0,
);
try {
$args = wp_parse_args( $args, $default_args );
$order = new WC_Order( $args['order_id'] );
// Update props that were set (not null)
if ( ! is_null( $args['parent'] ) ) {
$order->set_parent_id( absint( $args['parent'] ) );
}
if ( ! is_null( $args['status'] ) ) {
$order->set_status( $args['status'] );
}
if ( ! is_null( $args['customer_note'] ) ) {
$order->set_customer_note( $args['customer_note'] );
}
if ( ! is_null( $args['customer_id'] ) ) {
$order->set_customer_id( is_numeric( $args['customer_id'] ) ? absint( $args['customer_id'] ) : 0 );
}
if ( ! is_null( $args['created_via'] ) ) {
$order->set_created_via( sanitize_text_field( $args['created_via'] ) );
}
if ( ! is_null( $args['cart_hash'] ) ) {
$order->set_cart_hash( sanitize_text_field( $args['cart_hash'] ) );
}
// Update other order props set automatically
$order->set_currency( get_woocommerce_currency() );
$order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
$order->set_customer_ip_address( WC_Geolocation::get_ip_address() );
$order->set_customer_user_agent( wc_get_user_agent() );
$order->save();
} catch ( Exception $e ) {
return new WP_Error( 'error', $e->getMessage() );
}
return $order;
}
wc_create();