Fix merge conflicts

This commit is contained in:
Emili Castells Guasch 2023-08-30 15:57:03 +02:00
commit eedcbea51b
117 changed files with 5964 additions and 447 deletions

View file

@ -0,0 +1,39 @@
<?php
/**
* The compatibility module.
*
* @package WooCommerce\PayPalCommerce\Compat
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Compat;
use WC_Order;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
trait AdminContextTrait {
/**
* Checks if current post id is from a PayPal order.
*
* @return bool
*/
private function is_paypal_order_edit_page(): bool {
$post_id = wc_clean( wp_unslash( $_GET['id'] ?? $_GET['post'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! $post_id ) {
return false;
}
$order = wc_get_order( $post_id );
if ( ! is_a( $order, WC_Order::class ) ) {
return false;
}
if ( ! $order->get_meta( PayPalGateway::ORDER_ID_META_KEY ) ) {
return false;
}
return true;
}
}

View file

@ -455,15 +455,20 @@ class CompatModule implements ModuleInterface {
* @return void
*/
protected function fix_page_builders(): void {
if ( $this->is_elementor_pro_active() || $this->is_divi_theme_active() ) {
add_filter(
'woocommerce_paypal_payments_single_product_renderer_hook',
function(): string {
return 'woocommerce_after_add_to_cart_form';
},
5
);
}
add_action(
'init',
function() {
if ( $this->is_elementor_pro_active() || $this->is_divi_theme_active() ) {
add_filter(
'woocommerce_paypal_payments_single_product_renderer_hook',
function(): string {
return 'woocommerce_after_add_to_cart_form';
},
5
);
}
}
);
}
/**

View file

@ -7,6 +7,8 @@
namespace WooCommerce\PayPalCommerce\Compat\PPEC;
use Automattic\WooCommerce\Utilities\OrderUtil;
/**
* Helper class with various constants associated to the PayPal Express Checkout plugin, as well as methods for figuring
* out the status of the gateway.
@ -73,16 +75,25 @@ class PPECHelper {
}
global $wpdb;
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT 1 FROM {$wpdb->posts} p JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID
if ( class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() ) {
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT 1 FROM {$wpdb->wc_orders} WHERE payment_method = %s",
self::PPEC_GATEWAY_ID
)
);
} else {
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT 1 FROM {$wpdb->posts} p JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID
WHERE p.post_type = %s AND p.post_status != %s AND pm.meta_key = %s AND pm.meta_value = %s LIMIT 1",
'shop_subscription',
'trash',
'_payment_method',
self::PPEC_GATEWAY_ID
)
);
'shop_subscription',
'trash',
'_payment_method',
self::PPEC_GATEWAY_ID
)
);
}
set_transient(
'ppcp_has_ppec_subscriptions',

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Compat\PPEC;
use Automattic\WooCommerce\Utilities\OrderUtil;
use stdClass;
use WooCommerce\PayPalCommerce\Subscription\RenewalHandler;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
@ -183,22 +184,29 @@ class SubscriptionsHandler {
return true;
}
// Are we on the WC > Subscriptions screen?
// phpcs:ignore WordPress.Security.NonceVerification
$post_type = wc_clean( wp_unslash( $_GET['post_type'] ?? $_POST['post_type'] ?? '' ) );
if ( $post_type === 'shop_subscription' ) {
return true;
}
// Are we editing an order or subscription tied to PPEC?
// phpcs:ignore WordPress.Security.NonceVerification
$order_id = wc_clean( wp_unslash( $_GET['post'] ?? $_POST['post_ID'] ?? '' ) );
$order_id = wc_clean( wp_unslash( $_GET['id'] ?? $_GET['post'] ?? $_POST['post_ID'] ?? '' ) );
if ( $order_id ) {
$order = wc_get_order( $order_id );
return ( $order && PPECHelper::PPEC_GATEWAY_ID === $order->get_payment_method() );
}
// Are we on the WC > Subscriptions screen?
/**
* Class exist in WooCommerce.
*
* @psalm-suppress UndefinedClass
*/
$post_type_or_page = class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled()
// phpcs:ignore WordPress.Security.NonceVerification
? wc_clean( wp_unslash( $_GET['page'] ?? '' ) )
// phpcs:ignore WordPress.Security.NonceVerification
: wc_clean( wp_unslash( $_GET['post_type'] ?? $_POST['post_type'] ?? '' ) );
if ( $post_type_or_page === 'shop_subscription' || $post_type_or_page === 'wc-orders--shop_subscription' ) {
return true;
}
return false;
}
}