duananyu9231 2018-07-19 18:14
浏览 37
已采纳

在php wordpress中创建取消订阅按钮

I want to add an unsubscribe button to the “account details” in woocommerce that will go into user_meta and change that user’s meta_key of newsletter from true to false (it is automatically set to true right now when registering). What steps should I take to do so?

  • 写回答

1条回答 默认 最新

  • douyicao2199 2018-07-19 20:10
    关注

    Have an anchor tag leading to the page you want user to goto after clicking unsubscribe, and toss a query parameter in the URL like so:

    <a href="/new-page?email=<user email>">Unsubscribe</a>
    

    Now on that page have the following before page content loads wrapped in php of course.

    <?php
        //TOSS USERS EMAIL INTO VARIABLE
        $user_email = $_GET['email'];
        global $wpdb;
        $wpdb->update( 
                $wpdb->base_prefix.'user_meta', 
                array( 
                    'newsletter' => 'false'
                ),
                $user_email
            );
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52