diff --git a/includes/Orders.php b/includes/Orders.php index b587ec2..dd2f1af 100644 --- a/includes/Orders.php +++ b/includes/Orders.php @@ -11,6 +11,8 @@ namespace WCPOS\WooCommercePOS; use WC_Abstract_Order; +use WC_Product; +use WC_Product_Simple; class Orders { public function __construct() { @@ -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( @@ -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; + } } diff --git a/tests/includes/API/Test_HPOS_Orders_Controller.php b/tests/includes/API/Test_HPOS_Orders_Controller.php index fcb31a7..c89eb21 100644 --- a/tests/includes/API/Test_HPOS_Orders_Controller.php +++ b/tests/includes/API/Test_HPOS_Orders_Controller.php @@ -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' );