1

I am using woocommerce subscription plugin, and plugin have renew button on my account -> subscriptions. I want to hook in membership section. Code i find in reference is

    <?php if ( WCS_My_Account_Auto_Renew_Toggle::can_user_toggle_auto_renewal( $subscription ) ) : ?>
        <tr>
            <td><?php esc_html_e( 'Auto renew', 'woocommerce-subscriptions' ); ?></td>
            <td>
                <div class="wcs-auto-renew-toggle">
                    <?php

                    $toggle_classes = array( 'subscription-auto-renew-toggle', 'subscription-auto-renew-toggle--hidden' );

                    if ( $subscription->is_manual() ) {
                        $toggle_label     = __( 'Enable auto renew', 'woocommerce-subscriptions' );
                        $toggle_classes[] = 'subscription-auto-renew-toggle--off';

                        if ( WC_Subscriptions::is_duplicate_site() ) {
                            $toggle_classes[] = 'subscription-auto-renew-toggle--disabled';
                        }
                    } else {
                        $toggle_label     = __( 'Disable auto renew', 'woocommerce-subscriptions' );
                        $toggle_classes[] = 'subscription-auto-renew-toggle--on';
                    }?>
                    <a href="#" class="<?php echo esc_attr( implode( ' ' , $toggle_classes ) ); ?>" aria-label="<?php echo esc_attr( $toggle_label ) ?>"><i class="subscription-auto-renew-toggle__i" aria-hidden="true"></i></a>
                    <?php if ( WC_Subscriptions::is_duplicate_site() ) : ?>
                            <small class="subscription-auto-renew-toggle-disabled-note"><?php echo esc_html__( 'Using the auto-renewal toggle is disabled while in staging mode.', 'woocommerce-subscriptions' ); ?></small>
                    <?php endif; ?>
                </div>
            </td>
        </tr>
    <?php endif; ?>

Code I writed is:

    $users_subscriptions = wcs_get_users_subscriptions($user_id);

     if ($subscription->has_status(array('active', 'onhold', 'cancelled'))) {
          if($currentlang=="bg-BG") {
             echo '<div class="text-center"><a class="woocommerce-Button button" href="https://betinum.com/moyat-profil/?subscription_renewal_early='.$subscription->get_id().'&amp;subscription_renewal=true">Поднови</a></div>';
          } else {
             echo '<div class="text-center"><a class="woocommerce-Button button" href="https://betinum.com/en/my-account/?subscription_renewal_early='.$subscription->get_id().'&amp;subscription_renewal=true">Renew</a></div>';             
          }
      }
}

But seems, doesnt give a result :( Could anyone got me in right direction?

1 Answers1

0

All the renew switch process is made via ajax, you need to load the correct script and pass to it the subscription data.

Take a look here: https://github.com/wp-premium/woocommerce-subscriptions/blob/master/woocommerce-subscriptions.php#L369-L400

benedex82
  • 532
  • 2
  • 5
  • 18