Forums Forums Search & Filter Pro Get Woocommerce Shop Url

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #233881

    I am using a Search and Filter form on my Woocommerce shop page with the following settings:
    – Load results using Ajax
    – Make searches bookmarkable
    – Only use Ajax on the results page

    In case no products are found pursuant to a search, my template includes a button to go back to the products page. Instead of getting a clean / resetted url (www.example.com/products/), I get a shop page url seems to get automatically appended by search form data (www.example.com/products/?_sft_pa_products-by-range=amundsen). How can I get the clean url.

    I am using the following code to get the shop page url :
    `
    <?php
    $shop_page_id = get_option( ‘woocommerce_shop_page_id’ );
    $shop_page_url = get_permalink( wc_get_page_id( ‘shop’ ) );
    ?>
    <div class=”buttons”>
    <a href=”<?php esc_url( $shop_page_url ); ?>” class=”button button–primary”>
    <?php echo get_the_title($shop_page_id); ?>
    </a>
    </div>
    `
    Thanks

    Trevor
    #233907

    Hi

    What happens if you use this function instead?

    https://docs.woocommerce.com/wc-apidocs/function-wc_get_page_permalink.html

    Alternatively, you would need to trim the url (trim anything from and including the ? to the right). Like this I think:

    $shop_page_url = strtok(get_permalink( wc_get_page_id( 'shop' ) ),'?');

    Anonymous
    #233909

    Hi Trevor,

    Neither of the solutions work. Is there some way to plug in the reset button action here?

    Thanks

    Anonymous
    #233913

    Sorry, the second solution work. The first one (wc_get_page_permalink) sends me to the home url :

    esc_url( wc_get_page_permalink(wc_get_page_id( ‘shop’ )) )

    Anonymous
    #233915

    The first one works as well with wc_get_page_permalink(‘shop’ ).

    Thanks a lot

    Trevor
    #233918

    Thanks for getting back to me. I will close this thread for now.

Viewing 6 posts - 1 through 6 (of 6 total)