1

I have Woocommerce orders that are pending payment. At the moment when an order hits the automatic retry payment schedule it pulls the payment information from the subscription, which works great as the customer may have corrected their wrong details by then.

But in some cases, we need to manually retry the payment. When this is done, it doesn't pull the payment information from the subscription (as the customer may have corrected their details for it to go through).

Is there a hook/action that I can use to fire the following code? woocommerce_subscriptions_before_payment_retry doesn't seem to work.

add_action('woocommerce_subscriptions_before_payment_retry', 'remove_payment_details', 10, 2 );
function remove_payment_details( $order_id ){

  $order         = wc_get_order( $order_id ); // Order Object
  $subscriptions = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'any' ) ); // Array of subscriptions Objects

  foreach( $subscriptions as $subscription_id => $subscription ){
       $stripe_cust_id = $subscription->get_meta( '_stripe_customer_id');
       $stripe_src_id  = $subscription->get_meta( '_stripe_source_id' );

       $order->update_meta_data( '_stripe_customer_id', $stripe_cust_id );
       $order->update_meta_data( '_stripe_source_id', $stripe_src_id );
       $order->save();
  }

}

enter image description here

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Rob
  • 6,304
  • 24
  • 83
  • 189
  • I think that you should ask WooCommerce support or in 2 days add a big Bounty on this thread, Making some testable code example that can be reproduced. – LoicTheAztec Mar 12 '21 at 09:51
  • Have you tried firing the action through your code? https://wordpress.stackexchange.com/questions/54575/fire-a-hook-programmatically. `add_action` is supposed to be used by plugin developers to create a new hook for you. So i believe you should fire the action using `do_action(woocommerce_subscriptions_before_payment_retry, order_id)` – Tarun Lalwani Mar 15 '21 at 16:00

1 Answers1

0

Please check woocommerce_order_action_wcs_retry_renewal_payment hook. The hook is for "Retry Renewal Payment" handling, and you can use it.

add_action( 'woocommerce_order_action_wcs_retry_renewal_payment', 'custom_process_retry_renewal_payment_action_request', 20, 1 );

function custom_process_retry_renewal_payment_action_request( $order ) {
    // your code is here
}