Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jrick1229/53fa3eef5186a37cea388d61418760e5 to your computer and use it in GitHub Desktop.
Save jrick1229/53fa3eef5186a37cea388d61418760e5 to your computer and use it in GitHub Desktop.
Add a 'Change payment' button to the Subscriptions page in the My Account area
<?php
function wcs_add_change_payment_button_to_subscriptions_page($subscription) {
$actions = wcs_get_all_user_actions_for_subscription( $subscription, get_current_user_id() );
if(!empty($actions)){
foreach ( $actions as $key => $action ){
if(strtolower($action['name']) == "change payment"){
$changePaymentLink = esc_url( $action['url'] );
echo "<a href='$changePaymentLink' class='button change_payment_method'>".$action['name']."</a>";
}
}
}
}
add_action( 'woocommerce_my_subscriptions_actions', 'wcs_add_change_payment_button_to_subscriptions_page', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment