Wordpress/Woocommerce - pass data between two forms/pages











up vote
0
down vote

favorite












I've got an issue with my own code. Its main goal is to filter products of my woocommerce shop. So this is how it looks like:



function flt_product_search_func() {
?>

<form role="search" method="get" class="woocommerce-product-search" name="b2bform" id="b2bform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="container">
<div class="row">
<div class="col-lg-3">
<p class="search-field-name">Nazwa</p>
<input type="search" id="woocommerce-product-search-field-1" class="search-field" value="<?php echo get_search_query(); ?>" name="s" />
</div>
<div class="col-lg-3">
<p class="search-field-name">Marka</p>

<?php
$pabase = "pa_marka";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="<?php echo $pabase; ?>">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>

</div>
<div class="col-lg-3">
<p class="search-field-name">Typ</p>

<?php
$pabase = "pa_typ-wozka";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="<?php echo $pabase; ?>">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>

</div>
<div class="col-lg-3">
<p class="search-field-name">Udźwig od</p>
<?php
$pabase = "pa_udzwig";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_min_pa_udzwig">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<p class="search-field-name">Udźwig do</p>
<?php
$pabase = "pa_udzwig";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_max_pa_udzwig">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Napęd</p>
<?php
$pabase = "pa_naped";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="<?php echo $pabase; ?>">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Podnoszenie od</p>
<?php
$pabase = "pa_podnoszenie";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_min_pa_podnoszenie">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Podnoszenie do</p>
<?php
$pabase = "pa_podnoszenie";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_max_pa_podnoszenie">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<p class="search-field-name">Rok produkcji od</p>
<?php
$pabase = "pa_rok-produkcji";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_min_pa_rok-produkcji">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Rok produkcji do</p>
<?php
$pabase = "pa_rok-produkcji";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_max_pa_rok-produkcji">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Cena od</p>
<?php
$pabase = "rng_min_price";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?>
<input type="text" id="<?php echo $pabase; ?>" class="<?php echo $pabase; ?>" value="" name="<?php echo $pabase; ?>" />

</div>
<div class="col-lg-3">
<p class="search-field-name">Cena do</p>
<?php
$pabase = "rng_max_price";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?>
<input type="text" id="<?php echo $pabase; ?>" class="<?php echo $pabase; ?>" value="" name="<?php echo $pabase; ?>" />
</div>
</div>
<div class="row">
<div class="col-lg-3">
<p class="search-field-name">Maszt</p>
<?php
$pabase = "pa_maszt";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="<?php echo $pabase; ?>">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Motogodziny od</p>
<?php
$pabase = "pa_motogodziny";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_min_pa_motogodziny">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Motogodziny do</p>
<?php
$pabase = "pa_motogodziny";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_max_pa_motogodziny">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Kabina</p>
<?php
$pabase = "pa_kabina";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="<?php echo $pabase; ?>">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
</div>

<div class="row">
<div class="col-lg-3">
<p class="search-field-name">Przebieg od</p>
<?php
$pabase = "pa_przebieg";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_min_pa_przebieg">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3">
<p class="search-field-name">Przebieg do</p>
<?php
$pabase = "pa_przebieg";
$subheadingvalues = get_terms($pabase, array(
'hide_empty' => false,
));
?> <select name="rng_max_pa_przebieg">
<option label=" " selected disabled value></option>
<?php foreach ($subheadingvalues as $subheadingvalue): ?>
<option value="<?php echo $subheadingvalue->name; ?>">
<?php echo $subheadingvalue->name; ?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="col-lg-3"></div>
<div class="col-lg-3"></div>
</div>

<div class="row">
<div class="col-lg-12">
<button type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" class="takeright btnorange"><i class="fas fa-search"></i> <?php echo esc_html_x( 'Search', 'submit button', 'woocommerce' ); ?></button>
<button type="reset" value="<?php echo esc_attr_x( 'Wyczyść', 'reset button', 'woocommerce' ); ?>" id="resetbtn" class="takeright marginright1em btnorange" onClick="this.form.reset()"><?php echo esc_html_x( 'Wyczyść', 'reset button', 'woocommerce' ); ?></button>
<input type="hidden" name="post_type" value="product" />
</div>
</div>
</div>
</form>

<?php
}
add_shortcode( 'flt_product_search', 'flt_product_search_func' );


I'm pretty sure the code can be optimzed but still, is okeyish. I use this shortcode on my homepage, and when somebody submit the search it displays proper results (meaning -list products). But I've approached two issues:




  • what if I would like to show the same form (using same shortcode) on a woocomerce page (product listing)? It simply doesnt work. By doesnt work, it does not search products

  • what if I would like to pass selected values (in dropdowns) from homepage into search page (woocommerce product listing)? I have no idea how to achieve that


maybe I can utilize if ( isset( $_GET['submit'] ) ) {?



thanks for any suggestions










share|improve this question




























    up vote
    0
    down vote

    favorite












    I've got an issue with my own code. Its main goal is to filter products of my woocommerce shop. So this is how it looks like:



    function flt_product_search_func() {
    ?>

    <form role="search" method="get" class="woocommerce-product-search" name="b2bform" id="b2bform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <div class="container">
    <div class="row">
    <div class="col-lg-3">
    <p class="search-field-name">Nazwa</p>
    <input type="search" id="woocommerce-product-search-field-1" class="search-field" value="<?php echo get_search_query(); ?>" name="s" />
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Marka</p>

    <?php
    $pabase = "pa_marka";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="<?php echo $pabase; ?>">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>

    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Typ</p>

    <?php
    $pabase = "pa_typ-wozka";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="<?php echo $pabase; ?>">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>

    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Udźwig od</p>
    <?php
    $pabase = "pa_udzwig";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_min_pa_udzwig">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    </div>
    <div class="row">
    <div class="col-lg-3">
    <p class="search-field-name">Udźwig do</p>
    <?php
    $pabase = "pa_udzwig";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_max_pa_udzwig">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Napęd</p>
    <?php
    $pabase = "pa_naped";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="<?php echo $pabase; ?>">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Podnoszenie od</p>
    <?php
    $pabase = "pa_podnoszenie";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_min_pa_podnoszenie">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Podnoszenie do</p>
    <?php
    $pabase = "pa_podnoszenie";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_max_pa_podnoszenie">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    </div>
    <div class="row">
    <div class="col-lg-3">
    <p class="search-field-name">Rok produkcji od</p>
    <?php
    $pabase = "pa_rok-produkcji";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_min_pa_rok-produkcji">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Rok produkcji do</p>
    <?php
    $pabase = "pa_rok-produkcji";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_max_pa_rok-produkcji">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Cena od</p>
    <?php
    $pabase = "rng_min_price";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?>
    <input type="text" id="<?php echo $pabase; ?>" class="<?php echo $pabase; ?>" value="" name="<?php echo $pabase; ?>" />

    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Cena do</p>
    <?php
    $pabase = "rng_max_price";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?>
    <input type="text" id="<?php echo $pabase; ?>" class="<?php echo $pabase; ?>" value="" name="<?php echo $pabase; ?>" />
    </div>
    </div>
    <div class="row">
    <div class="col-lg-3">
    <p class="search-field-name">Maszt</p>
    <?php
    $pabase = "pa_maszt";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="<?php echo $pabase; ?>">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Motogodziny od</p>
    <?php
    $pabase = "pa_motogodziny";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_min_pa_motogodziny">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Motogodziny do</p>
    <?php
    $pabase = "pa_motogodziny";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_max_pa_motogodziny">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Kabina</p>
    <?php
    $pabase = "pa_kabina";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="<?php echo $pabase; ?>">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    </div>

    <div class="row">
    <div class="col-lg-3">
    <p class="search-field-name">Przebieg od</p>
    <?php
    $pabase = "pa_przebieg";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_min_pa_przebieg">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3">
    <p class="search-field-name">Przebieg do</p>
    <?php
    $pabase = "pa_przebieg";
    $subheadingvalues = get_terms($pabase, array(
    'hide_empty' => false,
    ));
    ?> <select name="rng_max_pa_przebieg">
    <option label=" " selected disabled value></option>
    <?php foreach ($subheadingvalues as $subheadingvalue): ?>
    <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
    </option>
    <?php endforeach;?>
    </select>
    </div>
    <div class="col-lg-3"></div>
    <div class="col-lg-3"></div>
    </div>

    <div class="row">
    <div class="col-lg-12">
    <button type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" class="takeright btnorange"><i class="fas fa-search"></i> <?php echo esc_html_x( 'Search', 'submit button', 'woocommerce' ); ?></button>
    <button type="reset" value="<?php echo esc_attr_x( 'Wyczyść', 'reset button', 'woocommerce' ); ?>" id="resetbtn" class="takeright marginright1em btnorange" onClick="this.form.reset()"><?php echo esc_html_x( 'Wyczyść', 'reset button', 'woocommerce' ); ?></button>
    <input type="hidden" name="post_type" value="product" />
    </div>
    </div>
    </div>
    </form>

    <?php
    }
    add_shortcode( 'flt_product_search', 'flt_product_search_func' );


    I'm pretty sure the code can be optimzed but still, is okeyish. I use this shortcode on my homepage, and when somebody submit the search it displays proper results (meaning -list products). But I've approached two issues:




    • what if I would like to show the same form (using same shortcode) on a woocomerce page (product listing)? It simply doesnt work. By doesnt work, it does not search products

    • what if I would like to pass selected values (in dropdowns) from homepage into search page (woocommerce product listing)? I have no idea how to achieve that


    maybe I can utilize if ( isset( $_GET['submit'] ) ) {?



    thanks for any suggestions










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I've got an issue with my own code. Its main goal is to filter products of my woocommerce shop. So this is how it looks like:



      function flt_product_search_func() {
      ?>

      <form role="search" method="get" class="woocommerce-product-search" name="b2bform" id="b2bform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
      <div class="container">
      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Nazwa</p>
      <input type="search" id="woocommerce-product-search-field-1" class="search-field" value="<?php echo get_search_query(); ?>" name="s" />
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Marka</p>

      <?php
      $pabase = "pa_marka";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>

      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Typ</p>

      <?php
      $pabase = "pa_typ-wozka";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>

      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Udźwig od</p>
      <?php
      $pabase = "pa_udzwig";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_udzwig">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      </div>
      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Udźwig do</p>
      <?php
      $pabase = "pa_udzwig";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_udzwig">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Napęd</p>
      <?php
      $pabase = "pa_naped";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Podnoszenie od</p>
      <?php
      $pabase = "pa_podnoszenie";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_podnoszenie">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Podnoszenie do</p>
      <?php
      $pabase = "pa_podnoszenie";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_podnoszenie">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      </div>
      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Rok produkcji od</p>
      <?php
      $pabase = "pa_rok-produkcji";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_rok-produkcji">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Rok produkcji do</p>
      <?php
      $pabase = "pa_rok-produkcji";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_rok-produkcji">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Cena od</p>
      <?php
      $pabase = "rng_min_price";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?>
      <input type="text" id="<?php echo $pabase; ?>" class="<?php echo $pabase; ?>" value="" name="<?php echo $pabase; ?>" />

      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Cena do</p>
      <?php
      $pabase = "rng_max_price";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?>
      <input type="text" id="<?php echo $pabase; ?>" class="<?php echo $pabase; ?>" value="" name="<?php echo $pabase; ?>" />
      </div>
      </div>
      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Maszt</p>
      <?php
      $pabase = "pa_maszt";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Motogodziny od</p>
      <?php
      $pabase = "pa_motogodziny";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_motogodziny">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Motogodziny do</p>
      <?php
      $pabase = "pa_motogodziny";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_motogodziny">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Kabina</p>
      <?php
      $pabase = "pa_kabina";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      </div>

      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Przebieg od</p>
      <?php
      $pabase = "pa_przebieg";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_przebieg">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Przebieg do</p>
      <?php
      $pabase = "pa_przebieg";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_przebieg">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3"></div>
      <div class="col-lg-3"></div>
      </div>

      <div class="row">
      <div class="col-lg-12">
      <button type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" class="takeright btnorange"><i class="fas fa-search"></i> <?php echo esc_html_x( 'Search', 'submit button', 'woocommerce' ); ?></button>
      <button type="reset" value="<?php echo esc_attr_x( 'Wyczyść', 'reset button', 'woocommerce' ); ?>" id="resetbtn" class="takeright marginright1em btnorange" onClick="this.form.reset()"><?php echo esc_html_x( 'Wyczyść', 'reset button', 'woocommerce' ); ?></button>
      <input type="hidden" name="post_type" value="product" />
      </div>
      </div>
      </div>
      </form>

      <?php
      }
      add_shortcode( 'flt_product_search', 'flt_product_search_func' );


      I'm pretty sure the code can be optimzed but still, is okeyish. I use this shortcode on my homepage, and when somebody submit the search it displays proper results (meaning -list products). But I've approached two issues:




      • what if I would like to show the same form (using same shortcode) on a woocomerce page (product listing)? It simply doesnt work. By doesnt work, it does not search products

      • what if I would like to pass selected values (in dropdowns) from homepage into search page (woocommerce product listing)? I have no idea how to achieve that


      maybe I can utilize if ( isset( $_GET['submit'] ) ) {?



      thanks for any suggestions










      share|improve this question















      I've got an issue with my own code. Its main goal is to filter products of my woocommerce shop. So this is how it looks like:



      function flt_product_search_func() {
      ?>

      <form role="search" method="get" class="woocommerce-product-search" name="b2bform" id="b2bform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
      <div class="container">
      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Nazwa</p>
      <input type="search" id="woocommerce-product-search-field-1" class="search-field" value="<?php echo get_search_query(); ?>" name="s" />
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Marka</p>

      <?php
      $pabase = "pa_marka";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>

      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Typ</p>

      <?php
      $pabase = "pa_typ-wozka";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>

      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Udźwig od</p>
      <?php
      $pabase = "pa_udzwig";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_udzwig">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      </div>
      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Udźwig do</p>
      <?php
      $pabase = "pa_udzwig";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_udzwig">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Napęd</p>
      <?php
      $pabase = "pa_naped";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Podnoszenie od</p>
      <?php
      $pabase = "pa_podnoszenie";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_podnoszenie">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Podnoszenie do</p>
      <?php
      $pabase = "pa_podnoszenie";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_podnoszenie">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      </div>
      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Rok produkcji od</p>
      <?php
      $pabase = "pa_rok-produkcji";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_rok-produkcji">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Rok produkcji do</p>
      <?php
      $pabase = "pa_rok-produkcji";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_rok-produkcji">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Cena od</p>
      <?php
      $pabase = "rng_min_price";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?>
      <input type="text" id="<?php echo $pabase; ?>" class="<?php echo $pabase; ?>" value="" name="<?php echo $pabase; ?>" />

      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Cena do</p>
      <?php
      $pabase = "rng_max_price";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?>
      <input type="text" id="<?php echo $pabase; ?>" class="<?php echo $pabase; ?>" value="" name="<?php echo $pabase; ?>" />
      </div>
      </div>
      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Maszt</p>
      <?php
      $pabase = "pa_maszt";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Motogodziny od</p>
      <?php
      $pabase = "pa_motogodziny";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_motogodziny">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Motogodziny do</p>
      <?php
      $pabase = "pa_motogodziny";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_motogodziny">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Kabina</p>
      <?php
      $pabase = "pa_kabina";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="<?php echo $pabase; ?>">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      </div>

      <div class="row">
      <div class="col-lg-3">
      <p class="search-field-name">Przebieg od</p>
      <?php
      $pabase = "pa_przebieg";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_min_pa_przebieg">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3">
      <p class="search-field-name">Przebieg do</p>
      <?php
      $pabase = "pa_przebieg";
      $subheadingvalues = get_terms($pabase, array(
      'hide_empty' => false,
      ));
      ?> <select name="rng_max_pa_przebieg">
      <option label=" " selected disabled value></option>
      <?php foreach ($subheadingvalues as $subheadingvalue): ?>
      <option value="<?php echo $subheadingvalue->name; ?>">
      <?php echo $subheadingvalue->name; ?>
      </option>
      <?php endforeach;?>
      </select>
      </div>
      <div class="col-lg-3"></div>
      <div class="col-lg-3"></div>
      </div>

      <div class="row">
      <div class="col-lg-12">
      <button type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" class="takeright btnorange"><i class="fas fa-search"></i> <?php echo esc_html_x( 'Search', 'submit button', 'woocommerce' ); ?></button>
      <button type="reset" value="<?php echo esc_attr_x( 'Wyczyść', 'reset button', 'woocommerce' ); ?>" id="resetbtn" class="takeright marginright1em btnorange" onClick="this.form.reset()"><?php echo esc_html_x( 'Wyczyść', 'reset button', 'woocommerce' ); ?></button>
      <input type="hidden" name="post_type" value="product" />
      </div>
      </div>
      </div>
      </form>

      <?php
      }
      add_shortcode( 'flt_product_search', 'flt_product_search_func' );


      I'm pretty sure the code can be optimzed but still, is okeyish. I use this shortcode on my homepage, and when somebody submit the search it displays proper results (meaning -list products). But I've approached two issues:




      • what if I would like to show the same form (using same shortcode) on a woocomerce page (product listing)? It simply doesnt work. By doesnt work, it does not search products

      • what if I would like to pass selected values (in dropdowns) from homepage into search page (woocommerce product listing)? I have no idea how to achieve that


      maybe I can utilize if ( isset( $_GET['submit'] ) ) {?



      thanks for any suggestions







      php wordpress woocommerce






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 22:43

























      asked Nov 11 at 21:36









      Paweł Skaba

      370830




      370830





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253477%2fwordpress-woocommerce-pass-data-between-two-forms-pages%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253477%2fwordpress-woocommerce-pass-data-between-two-forms-pages%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues