Created
October 26, 2020 13:06
-
-
Save madeincosmos/8867542e785518cfcb88fa453998f852 to your computer and use it in GitHub Desktop.
Simulate PayPal renewal IPN for WooCommerce Subscriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_order_actions', 'add_simulate_renewal_subscription_action' ); | |
function add_simulate_renewal_subscription_action( $actions ) { | |
global $theorder; | |
// Make sure we're in a subscription typeof order | |
if ( wcs_is_subscription( $theorder ) && ! $theorder->has_status( wcs_get_subscription_ended_statuses() ) ) { | |
// New action | |
$actions['wcs_simulate_renewal'] = esc_html__( 'Simulate Renewal IPN', 'woocommerce-subscriptions' ); | |
} | |
return $actions; | |
} | |
add_action( 'woocommerce_order_action_wcs_simulate_renewal', 'simulate_renewal_ipn_for_subscription' ); | |
function simulate_renewal_ipn_for_subscription( $subscription ) { | |
if ( wcs_is_subscription ( $subscription ) ) { | |
$subscription->update_status( 'on-hold' ); | |
$renewal_order = wcs_create_renewal_order( $order ); | |
$available_gateways = WC()->payment_gateways->get_available_payment_gateways(); | |
$renewal_order->set_payment_method( $available_gateways['paypal'] ); | |
$this->add_order_note( __( 'This is a fake renewal called from the subscription page. Marking payment complete.', 'woocommerce-subscriptions' ), $subscription, $transaction_details ); | |
$renewal_order->payment_complete( 'MADEUPTRANSACTIONID' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment