0

I'm trying to create the below function to check a user's for the metadata field "order_review_cards", and swap the value for Yes-no or no-yes.

Not sure why the code isn't working.

I can do:

update_user_meta( $user_id, 'order_review_cards', "YES"  );

and it will set the meta to YES, but if I go the if/else nothing updates.

function update_review_form_meta( $atts ){
        if (is_user_logged_in()) {
        $user_id = get_current_user_id();           
        $review_meta = get_user_meta($user_id, 'order_review_cards', TRUE);
            
            if ($review_meta == "No"){  
                update_user_meta( $user_id, 'order_review_cards', "YES"  );
            }elseif ($review_meta =="Yes"){
                update_user_meta( $user_id, 'order_review_cards', "NO"  );
            }           
        }
}
add_shortcode('order_review_cards_toggle','update_review_form_meta');
2
  • 1
    Why is this a shortcode? Updating user meta is really not an appropriate use for a shortcode. When is this code supposed to run? Apr 11 at 7:01
  • @JacobPeattie to be honest because I'm learning as I go and don't know AJAX etc. I've ended up just changing the function to only set the meta to "YES" and put the shortcode on a redirect page so it is triggered after completing a form. Probably a poor way to do this I know PHP is supposed to run with AJAX but this way is working for me right now.
    – Mitch C
    Apr 13 at 23:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.