Adding a Back button to Woocommerce product page

Hi

I would like to add a back to previous button to my product page. I found a forum page which relates to that topic and does provide the functionality i need

however it places the link in the position of the breadcrumbs (which I have turned off). I would actually like the button or link to appear under the price/category bit but above the long description info. Please can you help me with this?

Thanks in advance!

Hi There,

Thank you for writing in, Try replacing the hook that being used to put it into breadcrumbs (x_after_view_integrity__breadcrumbs), replace it with any of the WooCommerce Single Product Page hook.

Hope it helps,
Cheers!

Worked like a dream. Many thanks!

You’re most welcome!

Hello,
I need such a back button with history-back, too.
But I want it to appear on the breadcrumbs row.
The breadcrumbs shall appear left as usual, the back button on the right side.
Is that possible?
Thank you!

P.S. It would be great to place it where x-nav-articles is.

Hi,

To add it in your breadcrumbs section, you can try adding the code below in your child theme’s functions.php file.

  function x_breadcrumbs() {

    $args_items = array(
      'item_before'      => '',
      'item_after'       => '',
      'label_before'     => '',
      'label_after'      => '',
      'delimiter_before' => ' <span class="delimiter">',
      'delimiter_after'  => '</span> ',
      'delimiter_ltr'    => '<i class="x-icon-angle-right" data-x-icon="&#xf105;"></i>',
      'delimiter_rtl'    => '<i class="x-icon-angle-left" data-x-icon="&#xf104;"></i>',
      'current_class'    => 'current',
      'anchor_atts'      => array(),
      'include_meta'     => false,
    );

    $args_data = array(
      'home_label' => '<span class="home"><i class="x-icon-home" data-x-icon="&#xf015;"></i></span>',
    );
    

  
 



    if ( x_get_option( 'x_breadcrumb_display' ) ) {
      echo '<div class="x-breadcrumbs">' . x_breadcrumbs_items( x_breadcrumbs_data( $args_data ), $args_items ) . '</div>';
    }
    
    if ( x_is_product() ) {
       echo "<div class='cat-prod-link-back' style='float:right;'><a href='#' onClick='history.go(-1); return false;'>Back to previous page</a></div>";
    }

  }

Hope that helps.

Thank you. I built it into my code snippets plugin. Unfortunately there is an error message:

“The code snippet you are trying to save produced a fatal error on line 29:
Cannot redeclare x_breadcrumbs() (previously declared in /homepages/26/d11639858/htdocs/wordpress/wp-content/themes/x-child/functions.php:57)”

Is it OK to put it in a code snippet or do I have to put it directly into to functions.php?

Thank you!

Isn’t there something like add_filter missing in the code?

Hi there,

Please try this:

// Breadcrumbs Output
// =============================================================================

if ( ! function_exists( 'x_breadcrumbs' ) ) :

function x_breadcrumbs() {

    $args_items = array(
      'item_before'      => '',
      'item_after'       => '',
      'label_before'     => '',
      'label_after'      => '',
      'delimiter_before' => ' <span class="delimiter">',
      'delimiter_after'  => '</span> ',
      'delimiter_ltr'    => '<i class="x-icon-angle-right" data-x-icon="&#xf105;"></i>',
      'delimiter_rtl'    => '<i class="x-icon-angle-left" data-x-icon="&#xf104;"></i>',
      'current_class'    => 'current',
      'anchor_atts'      => array(),
      'include_meta'     => false,
    );

    $args_data = array(
      'home_label' => '<span class="home"><i class="x-icon-home" data-x-icon="&#xf015;"></i></span>',
    );

    if ( x_get_option( 'x_breadcrumb_display' ) ) {
      echo '<div class="x-breadcrumbs">' . x_breadcrumbs_items( x_breadcrumbs_data( $args_data ), $args_items ) . '</div>';
    }
    
    if ( x_is_product() ) {
       echo "<div class='cat-prod-link-back' style='float:right;'><a href='#' onClick='history.go(-1); return false;'>Back to previous page</a></div>";
    }

  }

else :

  // Deprecated Functions
  // --------------------
  // Kept for legacy purposes. If a user happens to have x_breadcrumbs()
  // overwritten in a child theme from an older release that was using these
  // functions, then a fatal error could occur if they do not exist. Going
  // forward, if updates need to be made to breadcrumbs, we suggest looking
  // into the various $args and filters available for x_breadcrumbs_data() and
  // x_breadcrumbs_items(), which should give you all of the control you need
  // without having to overwrite the function directly.

  if ( ! function_exists( 'x_get_breadcrumb_delimiter' ) ) :
    function x_get_breadcrumb_delimiter() {
      $is_ltr = ! is_rtl();
      return ' <span class="delimiter"><i class="x-icon-angle-' . ( ( $is_ltr ) ? 'right' : 'left' ) . '" data-x-icon="&#x' . ( ( $is_ltr ) ? 'f105' : 'f104' ) . ';"></i></span> ';
    }
  endif;

  if ( ! function_exists( 'x_get_breadcrumb_home_text' ) ) :
    function x_get_breadcrumb_home_text() {
      return '<span class="home"><i class="x-icon-home" data-x-icon="&#xf015;"></i></span>';
    }
  endif;

  if ( ! function_exists( 'x_get_breadcrumb_current_before' ) ) :
    function x_get_breadcrumb_current_before() {
      return '<span class="current">';
    }
  endif;

  if ( ! function_exists( 'x_get_breadcrumb_current_after' ) ) :
    function x_get_breadcrumb_current_after() {
      return '</span>';
    }
  endif;

endif;

Please add it in the functions.php file of the child theme.

Hope this helps.

In my functions.php there is already a code fragment which came from here:


Can I combine it?
Thank you!

I have made to combine it by myself. :slight_smile: Thank you!

Glad you’ve sorted it out :slight_smile: