我有几个产品,每种产品都与WooCommerce会员计划相关联,每个计划都限制了特定的帖子类别,因此客户只能在购买其会员计划的产品后才查看类别的帖子限制该类别。
现在,对于每篇新帖子,我想向购买该产品的客户发送一封电子邮件,限制了该类别的帖子,已发布了新帖子。有没有办法完成此操作?
要详细介绍这样的细节:
我有Product_A
和Product_B
2个邮政类别: Literature and Math
2会员计划:Plan_Prod_A and Plan_Prod_B
Plan_Prod_A
限制类别Literature
Plan_Prod_B restricts Math
要查看文献类别的帖子,客户必须购买product_a,这将使他访问会员计划plan_prod_a。
现在购买后,只要会员资格持续,我就需要它,对于文献类别中的任何新发布的帖子都必须通过帖子的链接发送给客户,以通知他已发布了新帖子。
我设法做到了,从长远来看会引起任何问题吗?
function post_unpublished( $new_status, $old_status, $post ) {
if ( $old_status != 'publish' && $new_status == 'publish' ) {
$user_id = get_current_user_id();
$post_id = $post->ID;
// if(get_post_meta($post_id,'_wc_memberships_force_public',true)=='yes') return true;
$args = array( 'status' => array( 'active' ));
$plans = wc_memberships_get_user_memberships( $user_id, $args );
$user_plans = array();
foreach($plans as $plan){
array_push($user_plans,$plan->plan_id);
}
$rules = wc_memberships()->get_rules_instance()->get_post_content_restriction_rules( $post_id );
foreach($rules as $rule){
if(in_array($rule->get_membership_plan_id(), $user_plans)){
$post_url = get_permalink( $post_id );
$subject = 'New Post';
$message = "A new post came out:nn";
$message .= $post->post_title . ": " . $post_url;
wp_mail( 'email', $subject, $message );
}
}
}
}
add_action( 'transition_post_status', 'post_unpublished', 10, 3 );