تابع ووکامرسی wc_create_order ایجاد سفارش جدید فروشگاه

تابع ووکامرسی wc_create_order – ایجاد سفارش یا order جدید فروشگاهی
Syntax – سینتکس
(WC_Order|WP_Error) wc_create_order( (array) $args = array() );
Parameters – پارامتر ها (1)
- 1- $args (array)
Usage – نحوه استفاده
if ( !function_exists( 'wc_create_order' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php';
}
// The args.
$args = array();
// NOTICE! Understand what this does before running.
$result = wc_create_order($args);
Defined – محل تعریف
/includes/wc-core-functions.php
function wc_create_order( $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;
}
versions – نسخه ها
از نسخه : 3.0.2
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر