Replace get_post_meta() with get_meta() for future-proofing

This commit is contained in:
George Burduli 2024-05-28 15:57:13 +04:00
parent 34acb8ce80
commit cf77c37d69
No known key found for this signature in database
GPG key ID: 572A97DFDA3D2E5C

View file

@ -94,18 +94,21 @@ class PayPalSubscriptionsModule implements ModuleInterface {
*
* @psalm-suppress MissingClosureParamType
*/
function ( $passed_validation, $product_id ) {
static function ( $passed_validation, $product_id ) {
if ( WC()->cart->is_empty() ) {
return $passed_validation;
}
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( get_post_meta( $cart_item['product_id'], 'ppcp_subscription_product', true ) ) {
$cart_product = wc_get_product( $cart_item['product_id'] );
if ( $cart_product && $cart_product->get_meta( 'ppcp_subscription_product', true ) ) {
wc_add_notice( __( 'You can only have one subscription product in your cart.', 'woocommerce-paypal-payments' ), 'error' );
return false;
}
if ( get_post_meta( $product_id, 'ppcp_subscription_product', true ) ) {
$product = wc_get_product( $product_id );
if ( $product && $product->get_meta( 'ppcp_subscription_product', true ) ) {
wc_add_notice( __( 'You cannot add a subscription product to a cart with other items.', 'woocommerce-paypal-payments' ), 'error' );
return false;
}