Skip to content

Commit

Permalink
Add fix for misc products where wc_get_product(0)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Apr 15, 2024
1 parent f491496 commit 56b71db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions includes/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace WCPOS\WooCommercePOS;

use WC_Abstract_Order;
use WC_Product;
use WC_Product_Simple;

class Orders {
public function __construct() {
Expand All @@ -21,6 +23,7 @@ public function __construct() {
add_filter( 'woocommerce_valid_order_statuses_for_payment_complete', array( $this, 'valid_order_statuses_for_payment_complete' ), 10, 2 );
add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'payment_complete_order_status' ), 10, 3 );
add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'hidden_order_itemmeta' ) );
add_filter( 'woocommerce_order_item_product', array( $this, 'order_item_product' ), 10, 2 );

// order emails
$admin_emails = array(
Expand Down Expand Up @@ -186,4 +189,22 @@ private function register_order_status(): void {
)
);
}

/**
*
*
* @param WC_Product|bool $product The product object or false if not found
* @param WC_Order_Item_Product $item The order item object
*
* @return WC_Product|bool
*/
public function order_item_product( $product, $item ) {
if ( ! $product ) {
// @TODO - add check for $item meta = '_woocommerce_pos_misc_product'
$product = new WC_Product_Simple();
$product->set_name( $item->get_name() );
}

return $product;
}
}
2 changes: 1 addition & 1 deletion tests/includes/API/Test_HPOS_Orders_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function setup(): void {
}

public function tearDown(): void {
$this->toggle_cot_feature_and_usage( $this->cot_state );
$this->toggle_cot_feature_and_usage( false );
$this->clean_up_cot_setup();

remove_all_filters( 'wc_allow_changing_orders_storage_while_sync_is_pending' );
Expand Down

0 comments on commit 56b71db

Please sign in to comment.