Created
November 13, 2013 19:27
-
-
Save thenbrent/7454868 to your computer and use it in GitHub Desktop.
Output a link to switch a subscription for the current user.
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
<?php | |
// Make sure WooCommerce Subscriptions is active | |
if ( class_exists( 'WC_Subscriptions_Switcher' ) ) { | |
// Get the key for the customer's current subscription | |
$subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order_id, $product_id ); | |
// Check if the current subscription can be switched by the customer | |
if ( WC_Subscriptions_Manager::can_subscription_be_changed_to( 'new-subscription', $subscription_key, get_current_user_id() ) ) { | |
// Print the link to initiate the switching process | |
printf( '<a href="%s">%s</a>', WC_Subscriptions_Switcher::get_switch_link( $subscription_key ), __( 'Choose a new subscription', 'textdomain' ) ); | |
} | |
} |
metamn
commented
Jul 3, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment