wooccommerce订阅在另一个地方添加续订按钮



我正在使用wooccommerce订阅插件,该插件在我的帐户上有续订按钮->订阅。我想加入会员部分。我在参考中找到的代码是

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

但似乎没有给出结果:(有人能把我带向正确的方向吗?

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

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

最新更新