@@ -381,13 +381,15 @@ public function maybe_update_source_on_subscription_order( $order, $source ) {
381
381
382
382
foreach ( $ subscriptions as $ subscription ) {
383
383
$ subscription_id = $ subscription ->get_id ();
384
- update_post_meta ( $ subscription_id , '_stripe_customer_id ' , $ source ->customer );
384
+ $ subscription -> update_meta_data ( '_stripe_customer_id ' , $ source ->customer );
385
385
386
386
if ( ! empty ( $ source ->payment_method ) ) {
387
- update_post_meta ( $ subscription_id , '_stripe_source_id ' , $ source ->payment_method );
387
+ $ subscription -> update_meta_data ( '_stripe_source_id ' , $ source ->payment_method );
388
388
} else {
389
- update_post_meta ( $ subscription_id , '_stripe_source_id ' , $ source ->source );
389
+ $ subscription -> update_meta_data ( '_stripe_source_id ' , $ source ->source );
390
390
}
391
+
392
+ $ subscription ->save ();
391
393
}
392
394
}
393
395
@@ -397,13 +399,14 @@ public function maybe_update_source_on_subscription_order( $order, $source ) {
397
399
* @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
398
400
*/
399
401
public function delete_resubscribe_meta ( $ resubscribe_order ) {
400
- delete_post_meta ( $ resubscribe_order ->get_id (), '_stripe_customer_id ' );
401
- delete_post_meta ( $ resubscribe_order ->get_id (), '_stripe_source_id ' );
402
+ $ resubscribe_order ->delete_meta_data ( '_stripe_customer_id ' );
403
+ $ resubscribe_order ->delete_meta_data ( '_stripe_source_id ' );
402
404
// For BW compat will remove in future.
403
- delete_post_meta ( $ resubscribe_order ->get_id (), '_stripe_card_id ' );
405
+ $ resubscribe_order ->delete_meta_data ( '_stripe_card_id ' );
404
406
// Delete payment intent ID.
405
- delete_post_meta ( $ resubscribe_order ->get_id (), '_stripe_intent_id ' );
407
+ $ resubscribe_order ->delete_meta_data ( '_stripe_intent_id ' );
406
408
$ this ->delete_renewal_meta ( $ resubscribe_order );
409
+ $ resubscribe_order ->save ();
407
410
}
408
411
409
412
/**
@@ -416,7 +419,7 @@ public function delete_renewal_meta( $renewal_order ) {
416
419
WC_Stripe_Helper::delete_stripe_net ( $ renewal_order );
417
420
418
421
// Delete payment intent ID.
419
- delete_post_meta ( $ renewal_order ->get_id (), '_stripe_intent_id ' );
422
+ $ renewal_order ->delete_meta_data ( '_stripe_intent_id ' );
420
423
421
424
return $ renewal_order ;
422
425
}
@@ -430,8 +433,9 @@ public function delete_renewal_meta( $renewal_order ) {
430
433
* @return void
431
434
*/
432
435
public function update_failing_payment_method ( $ subscription , $ renewal_order ) {
433
- update_post_meta ( $ subscription ->get_id (), '_stripe_customer_id ' , $ renewal_order ->get_meta ( '_stripe_customer_id ' , true ) );
434
- update_post_meta ( $ subscription ->get_id (), '_stripe_source_id ' , $ renewal_order ->get_meta ( '_stripe_source_id ' , true ) );
436
+ $ subscription ->update_meta_data ( '_stripe_customer_id ' , $ renewal_order ->get_meta ( '_stripe_customer_id ' , true ) );
437
+ $ subscription ->update_meta_data ( '_stripe_source_id ' , $ renewal_order ->get_meta ( '_stripe_source_id ' , true ) );
438
+ $ subscription ->save ();
435
439
}
436
440
437
441
/**
@@ -446,21 +450,22 @@ public function update_failing_payment_method( $subscription, $renewal_order ) {
446
450
*/
447
451
public function add_subscription_payment_meta ( $ payment_meta , $ subscription ) {
448
452
$ subscription_id = $ subscription ->get_id ();
449
- $ source_id = get_post_meta ( $ subscription_id , '_stripe_source_id ' , true );
453
+ $ source_id = $ subscription -> get_meta ( '_stripe_source_id ' , true );
450
454
451
455
// For BW compat will remove in future.
452
456
if ( empty ( $ source_id ) ) {
453
- $ source_id = get_post_meta ( $ subscription_id , '_stripe_card_id ' , true );
457
+ $ source_id = $ subscription -> get_meta ( '_stripe_card_id ' , true );
454
458
455
459
// Take this opportunity to update the key name.
456
- update_post_meta ( $ subscription_id , '_stripe_source_id ' , $ source_id );
457
- delete_post_meta ( $ subscription_id , '_stripe_card_id ' , $ source_id );
460
+ $ subscription ->update_meta_data ( '_stripe_source_id ' , $ source_id );
461
+ $ subscription ->delete_meta_data ( '_stripe_card_id ' );
462
+ $ subscription ->save ();
458
463
}
459
464
460
465
$ payment_meta [ $ this ->id ] = [
461
466
'post_meta ' => [
462
467
'_stripe_customer_id ' => [
463
- 'value ' => get_post_meta ( $ subscription_id , '_stripe_customer_id ' , true ),
468
+ 'value ' => $ subscription -> get_meta ( '_stripe_customer_id ' , true ),
464
469
'label ' => 'Stripe Customer ID ' ,
465
470
],
466
471
'_stripe_source_id ' => [
@@ -527,18 +532,19 @@ public function maybe_render_subscription_payment_method( $payment_method_to_dis
527
532
return $ payment_method_to_display ;
528
533
}
529
534
530
- $ stripe_source_id = get_post_meta ( $ subscription ->get_id (), '_stripe_source_id ' , true );
535
+ $ stripe_source_id = $ subscription ->get_meta ( '_stripe_source_id ' , true );
531
536
532
537
// For BW compat will remove in future.
533
538
if ( empty ( $ stripe_source_id ) ) {
534
- $ stripe_source_id = get_post_meta ( $ subscription ->get_id (), '_stripe_card_id ' , true );
539
+ $ stripe_source_id = $ subscription ->get_meta ( '_stripe_card_id ' , true );
535
540
536
541
// Take this opportunity to update the key name.
537
- update_post_meta ( $ subscription ->get_id (), '_stripe_source_id ' , $ stripe_source_id );
542
+ $ subscription ->update_meta_data ( '_stripe_source_id ' , $ stripe_source_id );
543
+ $ subscription ->save ();
538
544
}
539
545
540
546
$ stripe_customer = new WC_Stripe_Customer ();
541
- $ stripe_customer_id = get_post_meta ( $ subscription ->get_id (), '_stripe_customer_id ' , true );
547
+ $ stripe_customer_id = $ subscription ->get_meta ( '_stripe_customer_id ' , true );
542
548
543
549
// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
544
550
if ( ! $ stripe_customer_id || ! is_string ( $ stripe_customer_id ) ) {
@@ -557,15 +563,17 @@ public function maybe_render_subscription_payment_method( $payment_method_to_dis
557
563
558
564
// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
559
565
if ( ( ! $ stripe_customer_id || ! is_string ( $ stripe_customer_id ) ) && false !== $ subscription ->get_parent () ) {
560
- $ stripe_customer_id = get_post_meta ( $ subscription ->get_parent_id (), '_stripe_customer_id ' , true );
561
- $ stripe_source_id = get_post_meta ( $ subscription ->get_parent_id (), '_stripe_source_id ' , true );
566
+ $ parent_order = wc_get_order ( $ subscription ->get_parent_id () );
567
+ $ stripe_customer_id = $ parent_order ->get_meta ( '_stripe_customer_id ' , true );
568
+ $ stripe_source_id = $ parent_order ->get_meta ( '_stripe_source_id ' , true );
562
569
563
570
// For BW compat will remove in future.
564
571
if ( empty ( $ stripe_source_id ) ) {
565
- $ stripe_source_id = get_post_meta ( $ subscription -> get_parent_id (), '_stripe_card_id ' , true );
572
+ $ stripe_source_id = $ parent_order -> get_meta ( '_stripe_card_id ' , true );
566
573
567
574
// Take this opportunity to update the key name.
568
- update_post_meta ( $ subscription ->get_parent_id (), '_stripe_source_id ' , $ stripe_source_id );
575
+ $ parent_order ->update_meta_data ( '_stripe_source_id ' , $ stripe_source_id );
576
+ $ parent_order ->save ();
569
577
}
570
578
}
571
579
0 commit comments