我已经通过编写一个插件部分修复了这个问题,在该插件中,我生成了一个短代码,如果用户登录,我可以在成为成员后使用它进行编程。
function wp_add_missing_membership ( $user_id, $plan_id ) {
if ( ! function_exists( \'wc_memberships\' ) ) {
return;
}
$args = array(
// Enter the ID (post ID) of the plan to grant at registration
\'plan_id\' => $plan_id,
\'user_id\' => $user_id,
);
wc_memberships_create_user_membership( $args );
// Get the new membership
$user_membership = wc_memberships_get_user_membership( $user_id, $args[\'plan_id\'] );
// Add a note so we know how this was registered.
$user_membership->add_note( \'Membership imported from other site\' );
}
function has_woocommerce_subscription($the_user_id, $the_product_id, $the_status) {
$current_user = wp_get_current_user();
if (empty($the_user_id)) {
$the_user_id = $current_user->ID;
}
if (WC_Subscriptions_Manager::user_has_subscription( $the_user_id, $the_product_id, $the_status)) {
return true;
}
}
function bb_fixmembership ( $atts){
$a = shortcode_atts( array(\'plan\' => \'0\'), $atts );
$what_s_the_plan = $a[\'plan\'];
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
if (wc_memberships_is_user_active_member($user_id, \'student\')) {
// do nothing - all is good
} else {
wp_add_missing_membership($user_id, $what_s_the_plan);
}
}
}
add_shortcode( \'fixmembership\', \'bb_fixmembership\' );
现在,我需要将其与跨网站的订阅同步,这可能需要使用挂钩和用户元数据来实现。
我只是发布了一个答案,因为我没有看到大多数帖子被回复:)所以我想这可能会帮助其他人。。。
将在我完全修复它时发布。