【问题标题】:WooCommerce new post mail notification for product categoryWooCommerce 产品类别的新邮件通知
【发布时间】:2019-07-19 08:52:52
【问题描述】:

我有几个产品,每个产品都与 WooCommerce 会员计划相关联,每个计划都限制一个特定的帖子类别,因此客户只有在购买了会员计划限制该类别的产品后才能查看该类别的帖子。

现在,对于每个新帖子,我想向已购买该产品的客户发送一封电子邮件,限制该帖子类别,新帖子已发布。有没有办法做到这一点?

要了解更多细节,如下所示:

我有Product_AProduct_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 的权限。

现在购买后,只要会员资格持续,我就需要它,对于文学类别中任何新发布的帖子,必须向客户发送一封包含帖子链接的电子邮件,以通知他新帖子已发布.

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce


    【解决方案1】:

    我设法这样做了,但从长远来看会导致任何问题还是可以?

    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:\n\n";
                                $message .= $post->post_title . ": " . $post_url;
                                wp_mail( 'email', $subject, $message ); 
                            }
    
                        }       
    
    
                }
            }
            add_action( 'transition_post_status', 'post_unpublished', 10, 3 );
    

    【讨论】:

      猜你喜欢
      • 2020-10-03
      • 2021-03-22
      • 2019-05-30
      • 2018-06-04
      • 2022-01-02
      • 2019-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多