Tagged: cornerstone
-
AuthorPosts
-
April 24, 2016 at 3:54 pm #897720
Hi there
my site is http://www.wingdingevents.com.
I am trying to figure out a way to get a back button onto all my product pages.
As you will see, from the home page the user chooses a category
(eg vintage bands, http://www.wingdingevents.com/vintage-bands)then chooses an act
(example Dash Rip Crocodile http://www.wingdingevents.com/shop/swing-rat-pack-and-jazz/dash-rip-crocodile.I need to add a Back button on every product(act) page, so the user can get back easily to the category search results. Ideally this would sit on the same line as the breadcrumbs, perhaps in the middle of the page.
Can you suggest a solution?
Many thanks
Stirling
April 24, 2016 at 4:06 pm #897731btw it doesn’t need to be a button, it could be a link same as a breadcrumb
April 25, 2016 at 4:22 am #898315Hi There,
Thanks for posting in.
Please add the following code on your child theme functions.php file.// Add link to Product Category // ============================================================================= function add_backbutton(){ global $post, $product; if ( x_is_product() ) { $terms = get_the_terms( $post->ID, 'product_cat' ); $nterms = get_the_terms( $post->ID, 'product_tag' ); foreach ($terms as $term ) { $product_cat_id = $term->term_id; echo "<div class='cat-prod-link-back x-container max width'><a href='".get_term_link( $product_cat_id, 'product_cat' )."'>Link back to:".$term->name."</a></div>"; break; } } } add_action('x_after_view_integrity__breadcrumbs', 'add_backbutton');
Feel free to customize the link.
Hope this help.
April 25, 2016 at 5:31 am #898385Hi Lely
thats great thanks, unfortunately because of the way we’ve set up the site (using essential grid and pages as categories rather than the woocommerce ones), with the link will take the user back to the original woocommerce product category, rather than the search results page they came from. (many products are in more than 1 category, so that will go back to the alphabetic 1st category rather than the primary)
Would you mind revising that code to just say “back to previous page” or “back to search results” which takes the user back to the previous page they came from, just like a “Back” button.
Sorry about that, but many thanks for your help!
Regards
Stirling
April 25, 2016 at 6:30 am #898474heres an example btw
http://www.wingdingevents.com/shop/classical/marie-laure-violinist/
as this act is on classical page using essential grid, the link will take us to a different (woocommerce) categorty, so just a back link or back button is good. Thanks!
April 25, 2016 at 3:17 pm #899249Hi Stirling,
Please try this code:
// Add link to Previous Page // ============================================================================= function add_backbutton(){ if ( x_is_product() ) { echo "<div class='cat-prod-link-back x-container max width'><a href='#' onClick='history.go(-1); return false;'>Back to previous page</a></div>"; } } add_action('x_after_view_integrity__breadcrumbs', 'add_backbutton');
Hope this helps.
April 25, 2016 at 3:21 pm #899255Excellent, that works, thank you very much!
April 26, 2016 at 6:55 am #900150You’re welcome!
Always,
X -
AuthorPosts