Replace wp update post meta to wc update meta

This commit is contained in:
dinamiko 2022-10-24 12:35:31 +02:00
parent 37d5cae924
commit 5e42704dbc
5 changed files with 19 additions and 7 deletions

View file

@ -171,7 +171,11 @@ class OrderTrackingEndpoint {
throw $error;
}
update_post_meta( $order_id, '_ppcp_paypal_tracking_number', $data['tracking_number'] ?? '' );
$wc_order = wc_get_order( $order_id );
if ( is_a( $wc_order, WC_Order::class ) ) {
$wc_order->update_meta_data( '_ppcp_paypal_tracking_number', $data['tracking_number'] ?? '' );
$wc_order->save();
}
do_action( 'woocommerce_paypal_payments_after_tracking_is_added', $order_id, $response );
}
@ -300,7 +304,11 @@ class OrderTrackingEndpoint {
throw $error;
}
update_post_meta( $order_id, '_ppcp_paypal_tracking_number', $data['tracking_number'] ?? '' );
$wc_order = wc_get_order( $order_id );
if ( is_a( $wc_order, WC_Order::class ) ) {
$wc_order->update_meta_data( '_ppcp_paypal_tracking_number', $data['tracking_number'] ?? '' );
$wc_order->save();
}
do_action( 'woocommerce_paypal_payments_after_tracking_is_updated', $order_id, $response );
}

View file

@ -175,9 +175,9 @@ class SubscriptionModule implements ModuleInterface {
try {
$tokens = $payment_token_repository->all_for_user_id( $subscription->get_customer_id() );
if ( $tokens ) {
$subscription_id = $subscription->get_id();
$latest_token_id = end( $tokens )->id() ? end( $tokens )->id() : '';
update_post_meta( $subscription_id, 'payment_token_id', $latest_token_id, true );
$subscription->update_meta_data( 'payment_token_id', $latest_token_id );
$subscription->save();
}
} catch ( RuntimeException $error ) {
$message = sprintf(

View file

@ -151,7 +151,9 @@ class VaultedCreditCardHandler {
&& $this->subscription_helper->is_subscription_change_payment()
&& $saved_credit_card
) {
update_post_meta( $wc_order->get_id(), 'payment_token_id', $saved_credit_card );
$wc_order->update_meta_data( 'payment_token_id', $saved_credit_card );
$wc_order->save();
return $wc_order;
}

View file

@ -277,7 +277,8 @@ class CardButtonGateway extends \WC_Payment_Gateway {
if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) {
$saved_paypal_payment = filter_input( INPUT_POST, 'saved_paypal_payment', FILTER_SANITIZE_STRING );
if ( $saved_paypal_payment ) {
update_post_meta( $order_id, 'payment_token_id', $saved_paypal_payment );
$wc_order->update_meta_data( 'payment_token_id', $saved_paypal_payment );
$wc_order->save();
return $this->handle_payment_success( $wc_order );
}

View file

@ -425,7 +425,8 @@ class PayPalGateway extends \WC_Payment_Gateway {
if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) {
$saved_paypal_payment = filter_input( INPUT_POST, 'saved_paypal_payment', FILTER_SANITIZE_STRING );
if ( $saved_paypal_payment ) {
update_post_meta( $order_id, 'payment_token_id', $saved_paypal_payment );
$wc_order->update_meta_data( 'payment_token_id', $saved_paypal_payment );
$wc_order->save();
return $this->handle_payment_success( $wc_order );
}