Skip to content

Commit

Permalink
fix issue with created_via being overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Dec 22, 2023
1 parent 8db99ed commit 50cfa23
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions includes/API/Orders_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions woocommerce-pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="http://wordpress.org/plugins/woocommerce/">WooCommerce</a>.
* Version: 1.4.0-beta.4
* Version: 1.4.0-beta.5
* Author: kilbot
* Author URI: http://wcpos.com
* Text Domain: woocommerce-pos
Expand All @@ -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'
Expand Down

0 comments on commit 50cfa23

Please sign in to comment.