Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当客户在Woocommerce中取消订阅时删除用户_Php_Wordpress_Woocommerce_Woocommerce Subscriptions - Fatal编程技术网

Php 当客户在Woocommerce中取消订阅时删除用户

Php 当客户在Woocommerce中取消订阅时删除用户,php,wordpress,woocommerce,woocommerce-subscriptions,Php,Wordpress,Woocommerce,Woocommerce Subscriptions,当客户单击“取消订阅”时,他们仍然可以登录“我的帐户”部分,但我想让用户无法访问“我的帐户”部分中的任何内容。从这一点上,我想让功能“如果用户取消付款,它也会删除帐户”使他们无法访问,所以我尝试调查并编写下面的代码 add_action( 'woocommerce_order_status_cancelled', 'custom_woocommerce_auto_delete_user' ); function custom_woocommerce_auto_dele

当客户单击“取消订阅”时,他们仍然可以登录“我的帐户”部分,但我想让用户无法访问“我的帐户”部分中的任何内容。从这一点上,我想让功能“如果用户取消付款,它也会删除帐户”使他们无法访问,所以我尝试调查并编写下面的代码

    add_action( 'woocommerce_order_status_cancelled', 
    'custom_woocommerce_auto_delete_user' );

    function custom_woocommerce_auto_delete_user( $order_id ) {
        global $woocommerce;
        $order = new WC_Order( $order_id );
        $order_status = $order->get_status();
       if ( !$order_id )
            return false;
       if ('cancelled' == $order_status) {
         $current_user = wp_get_current_user();
            wp_delete_user( $current_user->ID,true );
       return true;
       }
   return false;
  }

然而,我只是woocommerce的初学者,我不知道哪种解决方案最适合这个问题。我很高兴有人来回复我:)

你说的“它不起作用”到底是什么意思?@NicoHaase我的意思是,我尝试在我的帐户页面的顺序上单击“取消”,用户仍然可以登录。你能进一步解释并添加问题的上下文吗?给定的代码是否被调用?在哪些情况下执行不符合您的期望?@NicoHaase当用户取消付款时,我们可以在delete user上创建自定义函数吗?也许您可以-只需编写一些代码;)既然您已经这么做了,那么给定的代码有什么问题?