mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Add HPOS compatibility to all metaboxes
This commit is contained in:
parent
52f6505eca
commit
a7bf718271
3 changed files with 25 additions and 6 deletions
|
@ -20,7 +20,7 @@ trait AdminContextTrait {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function is_paypal_order_edit_page(): bool {
|
private function is_paypal_order_edit_page(): bool {
|
||||||
$post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
$post_id = wc_clean( wp_unslash( $_GET['id'] ?? $_GET['post'] ?? '' ) );
|
||||||
if ( ! $post_id ) {
|
if ( ! $post_id ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\OrderTracking;
|
namespace WooCommerce\PayPalCommerce\OrderTracking;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
|
||||||
use WooCommerce\PayPalCommerce\Compat\AdminContextTrait;
|
use WooCommerce\PayPalCommerce\Compat\AdminContextTrait;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||||
|
@ -102,7 +103,16 @@ class OrderTrackingModule implements ModuleInterface {
|
||||||
* @psalm-suppress MissingClosureParamType
|
* @psalm-suppress MissingClosureParamType
|
||||||
*/
|
*/
|
||||||
function( $post_type ) use ( $c ) {
|
function( $post_type ) use ( $c ) {
|
||||||
if ( $post_type !== 'shop_order' || ! $this->is_paypal_order_edit_page() ) {
|
/**
|
||||||
|
* Class and function exist in WooCommerce.
|
||||||
|
*
|
||||||
|
* @psalm-suppress UndefinedClass
|
||||||
|
* @psalm-suppress UndefinedFunction
|
||||||
|
*/
|
||||||
|
$screen = wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
|
||||||
|
? wc_get_page_screen_id( 'shop-order' )
|
||||||
|
: 'shop_order';
|
||||||
|
if ( $post_type !== $screen || ! $this->is_paypal_order_edit_page() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +121,7 @@ class OrderTrackingModule implements ModuleInterface {
|
||||||
'ppcp_order-tracking',
|
'ppcp_order-tracking',
|
||||||
__( 'Tracking Information', 'woocommerce-paypal-payments' ),
|
__( 'Tracking Information', 'woocommerce-paypal-payments' ),
|
||||||
array( $meta_box_renderer, 'render' ),
|
array( $meta_box_renderer, 'render' ),
|
||||||
'shop_order',
|
$screen,
|
||||||
'side'
|
'side'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -227,12 +227,21 @@ class SubscriptionModule implements ModuleInterface {
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'add_meta_boxes',
|
'add_meta_boxes',
|
||||||
function( string $post_type, WP_Post $post ) use ( $c ) {
|
/**
|
||||||
if ( $post_type !== 'shop_subscription' ) {
|
* Param types removed to avoid third-party issues.
|
||||||
|
*
|
||||||
|
* @psalm-suppress MissingClosureParamType
|
||||||
|
*/
|
||||||
|
function( string $post_type, $post_or_order_object ) use ( $c ) {
|
||||||
|
$order = ( $post_or_order_object instanceof WP_Post )
|
||||||
|
? wc_get_order( $post_or_order_object->ID )
|
||||||
|
: $post_or_order_object;
|
||||||
|
|
||||||
|
if ( ! is_a( $order, WC_Order::class ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscription = wcs_get_subscription( $post->ID );
|
$subscription = wcs_get_subscription( $order->get_id() );
|
||||||
if ( ! is_a( $subscription, WC_Subscription::class ) ) {
|
if ( ! is_a( $subscription, WC_Subscription::class ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue