Forums › Forums › Search & Filter Pro › Get Woocommerce Shop Url
- This topic has 5 replies, 2 voices, and was last updated 5 years, 2 months ago by
Trevor.
-
Anonymous(Private) February 13, 2020 at 4:44 pm #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 pageIn 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>
`
ThanksTrevor(Private) February 14, 2020 at 10:06 am #233907Hi
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' ) ),'?');
-
AuthorPosts