0

How to set a WP-Form to show/hide content for logged in users based on the choices in the form that they made in the WP-form ?

Please help me guys - i am stuck big time for like 2 weeks and cant figure out anything. I did try everything from different plugins to writing a custom codes and nothing worked.

The problem in detail:

  1. User needs to register -> login.
  2. User needs to fill out a WP-form in my-account page where the user needs to choose one of 10 different options with different urls.
  3. When the user then goes to /my-account page or logs in later he should see only the button to the page based on his choice from the filling of the form the first time. Also the form needs to be invisible if the user already submitted it.

My set up: Wordpress website with woocommerce /my-account page. Plugin WP-forms and plugins elementor pro installed. I can get another plugins if you think i need them for this task. Thank you in advance for your help. Any advice is appriciated. I am stuck for 2 weeks on the same problem and i have a huuuuge problem. Thanks in advance for your help one more time. PS: for anyone who can help me please leave me your email - ill contact you to buy you a cofee or something... I am really really stuck and need help badly .

thanks in advance one more time.

i did try WP-forms plugin, elementor pro, wp-bakery builder, customize woocommerce my account page plugins, plugin that shows different things based on user role( but i cant make the wp-form to accept different user roles based on the different form fields checked before submitting it), and many various codes like :

Here are some examples(but i did try like 30-40 different codes with small variations and nothing helped):

typefunction add_product_button_to_account_page() {
  // Get the logged-in user's product selection
  $user_id = get_current_user_id();
  $selected_products = get_user_meta( $user_id, 'selected_products', true );
  
  // Make sure $selected_products is an array
  if ( ! is_array( $selected_products ) ) {
    $selected_products = array();
  }
  
  // Output button based on product selection
  switch ( true ) {
    case in_array( 'PBS-14', $selected_products ):
      echo '<a href="/product/pbs-14/" class="button">View PBS-14</a>';
      break;
    case in_array( '320 Mini', $selected_products ):
      echo '<a href="/product/320-mini/" class="button">View 320 Mini</a>';
      break;
    case in_array( 'True Core 1280', $selected_products ):
      echo '<a href="/product/true-core-1280/" class="button">View True Core 1280</a>';
      break;
    case in_array( 'Hawk 640 50', $selected_products ):
      echo '<a href="/product/hawk-640-50/" class="button">View Hawk 640 50</a>';
      break;
    case in_array( 'Hawk 640 75', $selected_products ):
      echo '<a href="/product/hawk-640-75/" class="button">View Hawk 640 75</a>';
      break;
    default:
      break;
  }
} 

Or this:

type<?php
function my_custom_redirect( $confirmation, $form, $entry, $ajax ) {
    $checkbox_value = rgar( $entry, 'checkbox_field_that_needs_to_be_added' );
    if ( ! empty( $checkbox_value ) ) {
        if ( $checkbox_value == 'option1' ) {
            $redirect_url = '/#producturl1';
        } elseif ( $checkbox_value == 'option2' ) {
            $redirect_url = '/#producturl2';
        } elseif ( $checkbox_value == 'option3' ) {
            $redirect_url = '/#producturl3';
        }
        $confirmation = array( 'redirect' => $redirect_url );
    }
    return $confirmation;
}
add_filter( 'gform_confirmation', 'my_custom_redirect', 10, 4 );
?>


<?php
function my_custom_button() {
    $user_id = get_current_user_id();
    $checkbox_value = get_user_meta( $user_id, 'checkbox_field_that_needs_to_be_added', true );
    if ( ! empty( $checkbox_value ) ) {
        if ( $checkbox_value == 'option1' ) {
            $button_url = '/#producturl1';
        } elseif ( $checkbox_value == 'option2' ) {
            $button_url = '/#producturl2';
        } elseif ( $checkbox_value == 'option3' ) {
            $button_url = '/#producturl3';
        }
        ?>
        <a href="<?php echo $button_url; ?>" class="button">View Product</a>
        <?php
    }
}
add_action( 'woocommerce_account_navigation', 'my_custom_button' );
?>

0 Answers0