• Hello,

    I am not an expert in editing php files. Is there a simple way to change the “Back to Category” button on the PRODUCT VIEW.

    Description:
    The button I am talking about is appearing when you are within a single product view. For me the link appears on the top left and days “Back to Category” but I want to change it to direct people to the general shop, and not the category.

    class=”product_header clearfix” > class=”cat_back_btn headerfont”

    Thank you in advance.
    Ben

    https://www.ads-software.com/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Hi Ben,

    When you install Woocommerce, you will find a folder woocommerce in your theme (I use theme Virtue). In folder woocommerce, open file single-product.php
    find a code like this

    $terms = wp_get_post_terms( $post->ID, 'product_cat', array( 'orderby' => 'parent', 'order' => 'DESC' ) );
    if(!empty($terms)) {
    	$main_term = $terms[0];
    } else {
    	$main_term = "";
    }
    if($main_term) {
    	echo '<div class="cat_back_btn headerfont"><i class="icon-arrow-left"></i> '.__('Back to', 'virtue').' <a href="'.get_term_link($main_term->slug, 'product_cat').'">'.$main_term->name.'</a></div>';
    } else {
    	echo '<div class="cat_back_btn headerfont"><i class="icon-arrow-left"></i> '.__('Back to', 'virtue').' <a href="'.get_permalink( woocommerce_get_page_id( 'shop' ) ).'">'.__('Shop','virtue').'</a></div>';
    	}

    Link above create a logic, when variable $main_term has a value from ID product, it will create link to product category. If not, it will create link to shop.

    On your question, you want every link will redirect to shop. You easily remove some line of code above. So it will look like this

    echo '<div class="cat_back_btn headerfont"><i class="icon-arrow-left"></i> '.__('Back to', 'virtue').' <a href="'.get_permalink( woocommerce_get_page_id( 'shop' ) ).'">'.__('Shop','virtue').'</a></div>';

    text virtue on code above refer your theme slug name. Please make sure that is your current theme.

Viewing 1 replies (of 1 total)
  • The topic ‘Back to Category – change to – back to shop instead’ is closed to new replies.