diff --git a/includes/API/Orders_Controller.php b/includes/API/Orders_Controller.php index 5b24ef7..bed4f58 100644 --- a/includes/API/Orders_Controller.php +++ b/includes/API/Orders_Controller.php @@ -44,6 +44,13 @@ class Orders_Controller extends WC_REST_Orders_Controller { */ protected $wcpos_request; + /** + * Whether we are creating a new order. + * + * @var bool + */ + private $is_creating = false; + /** * Constructor. */ @@ -133,7 +140,7 @@ public function get_item_schema() { /** - * Create a single item. + * Create a single order. * * @param WP_REST_Request $request Full details about the request. * @@ -145,6 +152,9 @@ public function create_item( $request ) { return $valid_email; } + // Set the creating flag, used in woocommerce_before_order_object_save + $this->is_creating = true; + // Proceed with the parent method to handle the creation return parent::create_item( $request ); } @@ -486,7 +496,7 @@ public function wcpos_order_get_items( array $items, WC_Order $order, array $ite * @throws WC_Data_Exception */ public function wcpos_before_order_object_save( WC_Order $order ): void { - if ( 0 === $order->get_id() ) { + if ( $this->is_creating ) { $order->set_created_via( PLUGIN_NAME ); } diff --git a/package.json b/package.json index 5eb2552..c47f5b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wcpos/woocommerce-pos", - "version": "1.4.0-beta.4", + "version": "1.4.0-beta.5", "description": "A simple front-end for taking WooCommerce orders at the Point of Sale.", "main": "index.js", "workspaces": { diff --git a/woocommerce-pos.php b/woocommerce-pos.php index ba3d0d7..5635d15 100644 --- a/woocommerce-pos.php +++ b/woocommerce-pos.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce POS * Plugin URI: https://wordpress.org/plugins/woocommerce-pos/ * Description: A simple front-end for taking WooCommerce orders at the Point of Sale. Requires WooCommerce. - * Version: 1.4.0-beta.4 + * Version: 1.4.0-beta.5 * Author: kilbot * Author URI: http://wcpos.com * Text Domain: woocommerce-pos @@ -22,7 +22,7 @@ namespace WCPOS\WooCommercePOS; // Define plugin constants. -const VERSION = '1.4.0-beta.4'; +const VERSION = '1.4.0-beta.5'; const PLUGIN_NAME = 'woocommerce-pos'; const SHORT_NAME = 'wcpos'; \define( __NAMESPACE__ . '\PLUGIN_FILE', plugin_basename( __FILE__ ) ); // 'woocommerce-pos/woocommerce-pos.php'