Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #897720

    stirlingaustin
    Participant

    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

    #897731

    stirlingaustin
    Participant

    btw it doesn’t need to be a button, it could be a link same as a breadcrumb

    #898315

    Lely
    Moderator

    Hi 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.

    #898385

    stirlingaustin
    Participant

    Hi 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

    #898474

    stirlingaustin
    Participant

    heres 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!

    #899249

    Jade
    Moderator

    Hi 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.

    #899255

    stirlingaustin
    Participant

    Excellent, that works, thank you very much!

    #900150

    Lely
    Moderator

    You’re welcome!

    Always,
    X