diff --git a/changelog.txt b/changelog.txt index 7654600..180f320 100644 --- a/changelog.txt +++ b/changelog.txt @@ -727,10 +727,3 @@ Tested against: - [Tested Against] Woocommerce 8.5.2 - [Tested Against] PHP SDK 4.0.2 -= 3.0.1 - April 3 2024 = -- [Feature] Added support to High Performance Order Storage (HPOS). -- [Tested Against] PHP 8.2 -- [Tested Against] Wordpress 6.5 -- [Tested Against] Woocommerce 8.7.0 -- [Tested Against] PHP SDK 4.0.2 - diff --git a/includes/admin/class-wc-wallee-admin-document.php b/includes/admin/class-wc-wallee-admin-document.php index 229484a..7aeb93d 100644 --- a/includes/admin/class-wc-wallee-admin-document.php +++ b/includes/admin/class-wc-wallee-admin-document.php @@ -113,35 +113,50 @@ public static function add_buttons_to_overview( WC_Order $order ) { /** * Add WC Meta boxes. - * @see: https://woo.com/document/high-performance-order-storage/#section-8 */ public static function add_meta_box() { - $screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) - && wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() - ? wc_get_page_screen_id( 'shop-order' ) - : 'shop_order'; - add_meta_box( - 'woocommerce-order-wallee-documents', - __( 'wallee Documents', 'woo-wallee' ), + global $post; + if ( 'shop_order' !== $post->post_type ) { + return; + } + $order = WC_Order_Factory::get_order( $post->ID ); + $method = wc_get_payment_gateway_by_order( $order ); + if ( ! ( $method instanceof WC_Wallee_Gateway ) ) { + return; + } + $transaction_info = WC_Wallee_Entity_Transaction_Info::load_by_order_id( $order->get_id() ); + if ( $transaction_info->get_id() !== null && in_array( + $transaction_info->get_state(), array( - __CLASS__, - 'output', + \Wallee\Sdk\Model\TransactionState::COMPLETED, + \Wallee\Sdk\Model\TransactionState::FULFILL, + \Wallee\Sdk\Model\TransactionState::DECLINE, ), - $screen, - 'side', - 'default' - ); + true + ) ) { + add_meta_box( + 'woocommerce-order-wallee-documents', + __( 'wallee Documents', 'woo-wallee' ), + array( + __CLASS__, + 'output', + ), + 'shop_order', + 'side', + 'default' + ); + } } /** * Output the metabox. * - * @param WP_Post|WP_Order $post_or_order_object - * This object is provided by woocommerce when using its screen. + * @param WP_Post $post Post. */ - public static function output( $post_or_order_object ) { - $order = ( $post_or_order_object instanceof WP_Post ) ? wc_get_order( $post_or_order_object->ID ) : $post_or_order_object; + public static function output( $post ) { + global $post; + $order = WC_Order_Factory::get_order( $post->ID ); $method = wc_get_payment_gateway_by_order( $order ); if ( ! ( $method instanceof WC_Wallee_Gateway ) ) { return; diff --git a/includes/admin/class-wc-wallee-admin-transaction.php b/includes/admin/class-wc-wallee-admin-transaction.php index 8c62747..08a58f8 100644 --- a/includes/admin/class-wc-wallee-admin-transaction.php +++ b/includes/admin/class-wc-wallee-admin-transaction.php @@ -41,35 +41,45 @@ public static function init() { /** * Add WC Meta boxes. - * @see: https://woo.com/document/high-performance-order-storage/#section-8 */ public static function add_meta_box() { - $screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) - && wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() - ? wc_get_page_screen_id( 'shop-order' ) - : 'shop_order'; - add_meta_box( - 'woocommerce-order-wallee-transaction', - __( 'wallee Transaction', 'woocommerce-wallee' ), - array( - __CLASS__, - 'output', - ), - $screen, - 'normal', - 'default' - ); + global $post; + if ( 'shop_order' != $post->post_type ) { + return; + } + $order = WC_Order_Factory::get_order( $post->ID ); + $method = wc_get_payment_gateway_by_order( $order ); + if ( ! ( $method instanceof WC_Wallee_Gateway ) ) { + return; + } + $transaction_info = WC_Wallee_Entity_Transaction_Info::load_by_order_id( $order->get_id() ); + if ( $transaction_info->get_id() == null ) { + $transaction_info = WC_Wallee_Entity_Transaction_Info::load_newest_by_mapped_order_id( $order->get_id() ); + } + if ( $transaction_info->get_id() != null ) { + add_meta_box( + 'woocommerce-order-wallee-transaction', + __( 'wallee Transaction', 'woocommerc-wallee' ), + array( + __CLASS__, + 'output', + ), + 'shop_order', + 'normal', + 'default' + ); + } } /** * Output the metabox. * - * @param WP_Post|WP_Order $post_or_order_object - * This object is provided by woocommerce when using its screen. + * @param WP_Post $post post data. */ - public static function output( $post_or_order_object ) { - $order = ( $post_or_order_object instanceof WP_Post ) ? wc_get_order( $post_or_order_object->ID ) : $post_or_order_object; + public static function output( $post ) { + global $post; + $order = WC_Order_Factory::get_order( $post->ID ); $method = wc_get_payment_gateway_by_order( $order ); if ( ! ( $method instanceof WC_Wallee_Gateway ) ) { return; @@ -119,7 +129,7 @@ public static function output( $post_or_order_object ) {