0
votes

I'm trying to use the shop page to display custom search results in woocommerce after a form submit.

So the scenario is:

  1. Someone, via a form, chooses ex: a product type.
  2. The page redirects to a separate php page to handle the result, hook into the query and redirect to shop page.

This is what my separate php page looks like:

if (isset('submit')){
    add_action('pre_get_posts', function($query){
        //my hook that doesn't work
    });

    wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
    exit;
}

The result is my shop page with all items. How can I hook into the shop to display a specific query of my own?

1
Well of course, you've added action then redirected. Your page which you redirected to won't have action registered. Find a way to add if after redirect actually happens - Igor Yavych

1 Answers

0
votes

What I ended up doing was, instead of trying to change the query, I sent filter parameters through the url like so:

wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) . '?filter_size=' . $size . '&filter_weight=' . $weight);
exit;