【问题标题】:woocommerce subscription add renewal button on another placewoocommerce 订阅在另一个地方添加续订按钮
【发布时间】:2021-06-14 19:51:59
【问题描述】:

我正在使用 woocommerce 订阅插件,并且插件在我的帐户上有更新按钮 -> 订阅。 我想挂在会员部分。 我在reference 中找到的代码是

    <?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; ?>

我写的代码是:

    $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>';             
          }
      }
}

但似乎没有给出结果:( 谁能让我找到正确的方向?

【问题讨论】:

  • 你解决了吗?如果是这样,您可以上传代码作为答案吗?

标签: php wordpress woocommerce woocommerce-subscriptions


【解决方案1】:

所有的续订切换过程都是通过ajax进行的,您需要加载正确的脚本并将订阅数据传递给它。

看这里:https://github.com/wp-premium/woocommerce-subscriptions/blob/master/woocommerce-subscriptions.php#L369-L400

【讨论】:

    猜你喜欢
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    • 2020-02-07
    • 2020-12-04
    • 2017-03-11
    • 2015-11-27
    相关资源
    最近更新 更多