0

我想知道课堂上是否有某种方法WC_Memberships_User_Membership可以获取取消会员资格的链接。

我获取 url 的方式将我带到 woocommerce 我的帐户/会员页面,而不是取消订阅的实际操作。

<?php
$memberships = wc_memberships_get_user_memberships();               
if ( $memberships ) {
    foreach( $memberships as $membership ) {
        echo '<p>Plan: ' . $membership->plan->name . '</p>';
        echo '<p>Since: ' . $membership->get_start_date('d-m-Y') . '</p>';
        echo '<p>Until: ' . $membership->get_end_date('d-m-Y') . '</p>';
        $url = 'https://poesicilina.com/?cancel_membership=' . $membership->id;
        echo '<p><a href="' . $url . '">Cancel membership</a></p>';
    }
}
4

1 回答 1

1
<?php
function  cancelbutton(){   
$user_id = get_current_user_id();

$memberships = wc_memberships_get_user_active_memberships($user_id);

foreach ($memberships as $membership => $val) {

$url = $val->get_cancel_membership_url();
echo "<a href='$url'>Cancel</a>";
};

add_shortcode( 'cancelbutton', 'cancelbutton' ); ?>

使用简码 [取消按钮]

于 2021-10-07T22:08:09.100 回答