• Resolved phpcoder123

    (@phpcoder123)


    Hello. I want to add a 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?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Below is a starting point and it’ll need a lot of work to get it working. Its unlikely you’ll get working code from the forum. PHP skills will be needed.

    // add content to the edit-account endpoint
    add_action( 'woocommerce_account_edit-account_endpoint', 'tp_edit_account_content' );
    function tp_edit_account_content() {
      $current_user_id = get_current_user_id();    
      $value = isset( $_POST['subscribe'] ) ? 1 : 0;
      update_user_meta( $user_id, 'subscribe', $value );
      print 'Your preference has been updated.'.PHP_EOL;
      print '<input type="checkbox" name="subscribe" value="'.$value.'" /> Subscribe';
    }
    Luminus Alabi

    (@luminus)

    Automattic Happiness Engineer

    @phpcoder123,

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Unsubscribe button that changes user_meta value’ is closed to new replies.