Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #780111

    bayne
    Participant

    Hi there!

    I am new to X Theme, and I absolutely love it! That said… I am having a bit of trouble.

    I have searched for solutions already on this forum and other places. However, I need a bit more specific help.

    1. What I would like to do is redirect “return to shop” to a custom url when cart is empty. I saw a post where someone successfully changed this, but didn’t share the exact details:
    https://community.theme.co/forums/topic/change-shop-link-in-breadcrumbs-to-custom-url-add-second-header/

    His (the guy in the post above) site works identical to how I would like mine to. Here is an example of the “return to shop” custom url I am looking for:
    http://test1.sassypantsdesign.com/cart/

    2. I would like to also edit breadcrumbs “the shop” url. Again, the guy in the post above’s breadcrumbs is what I’m looking to replicate. Here is an example of that as well (“shop” redirects to his custom shop page created with essential grid”:
    http://test1.sassypantsdesign.com/shop/notecards/10-assorted-dog-notecards-set-1/

    In woocommerce>settings>products>display, I can remove the shop page for it to look at, but that’s not really helping my issue. What I would like to do is create a custom shop page, like in the example site above, and have everything point to it.

    I am currently looking at appearance>editor>Theme Functions (functions.php) for coding solutions to this problem. Is this the right place to be looking?

    Thanks!

    #780113

    bayne
    Participant
    This reply has been marked as private.
    #780840

    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in! The return to shop button and the shop in the breadcrumb will all points to the shop page. You have to assign a page as your shop page in WooCommerce > Settings > Products > Display > Shop Page (http://prntscr.com/9z6hqe). If you do not assign any, the button and the breadcrumb will linked to none which would somehow result to an error 404.

    If you wish to do the same as the topic you have pointed out, because what you are trying to accomplish requires a template customization, we would like to suggest that you use a child theme first. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    Once your child theme is ready, please insert this code in your child theme’s functions.php

    function x_breadcrumbs() {
    
        if ( x_get_option( 'x_breadcrumb_display' ) ) {
    
          GLOBAL $post;
    
          $is_ltr         = ! is_rtl();
          $stack          = x_get_stack();
          $delimiter      = x_get_breadcrumb_delimiter();
          $home_text      = x_get_breadcrumb_home_text();
          $home_link      = home_url();
          $current_before = x_get_breadcrumb_current_before();
          $current_after  = x_get_breadcrumb_current_after();
          $page_title     = get_the_title();
          $blog_title     = get_the_title( get_option( 'page_for_posts', true ) );
    
          if ( ! is_404() ) {
            $post_parent = $post->post_parent;
          } else {
            $post_parent = '';
          }
    
          if ( X_WOOCOMMERCE_IS_ACTIVE ) {
            $shop_url   = x_get_shop_link();
            $shop_title = x_get_option( 'x_' . $stack . '_shop_title' );
            $shop_link  = '<a href="'. $shop_url .'">' . $shop_title . '</a>';
          }
    
          echo '<div class="x-breadcrumbs"><a href="' . $home_link . '">' . $home_text . '</a>' . $delimiter;
    
            if ( is_home() ) {
    
              echo $current_before . $blog_title . $current_after;
    
            } elseif ( is_category() ) {
    
              $the_cat = get_category( get_query_var( 'cat' ), false );
              if ( $the_cat->parent != 0 ) echo get_category_parents( $the_cat->parent, TRUE, $delimiter );
              echo $current_before . single_cat_title( '', false ) . $current_after;
    
            } elseif ( x_is_product_category() ) {
    
              if ( $is_ltr ) {
                echo $shop_link . $delimiter . $current_before . single_cat_title( '', false ) . $current_after;
              } else {
                echo $current_before . single_cat_title( '', false ) . $current_after . $delimiter . $shop_link;
              }
    
            } elseif ( x_is_product_tag() ) {
    
              if ( $is_ltr ) {
                echo $shop_link . $delimiter . $current_before . single_tag_title( '', false ) . $current_after;
              } else {
                echo $current_before . single_tag_title( '', false ) . $current_after . $delimiter . $shop_link;
              }
    
            } elseif ( is_search() ) {
    
              echo $current_before . __( 'Search Results for ', '__x__' ) . '“' . get_search_query() . '”' . $current_after;
    
            } elseif ( is_singular( 'post' ) ) {
    
              if ( get_option( 'page_for_posts' ) == is_front_page() ) {
                echo $current_before . $page_title . $current_after;
              } else {
                if ( $is_ltr ) {
                  echo '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</a>' . $delimiter . $current_before . $page_title . $current_after;
                } else {
                  echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</a>';
                }
              }
    
            } elseif ( x_is_portfolio() ) {
    
              echo $current_before . get_the_title() . $current_after;
    
            } elseif ( x_is_portfolio_item() ) {
    
              $link  = x_get_parent_portfolio_link();
              $title = x_get_parent_portfolio_title();
    
              if ( $is_ltr ) {
                echo '<a href="' . $link . '">' . $title . '</a>' . $delimiter . $current_before . $page_title . $current_after;
              } else {
                echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . $link . '">' . $title . '</a>';
              }
    
            } elseif ( x_is_product() ) {
    
              if ( $is_ltr ) {
                echo $shop_link . $delimiter . $current_before . $page_title . $current_after;
              } else {
                echo $current_before . $page_title . $current_after . $delimiter . $shop_link;
              }
    
            } elseif ( x_is_buddypress() ) {
    
              if ( bp_is_group() ) {
                echo '<a href="' . bp_get_groups_directory_permalink() . '">' . x_get_option( 'x_buddypress_groups_title' ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
              } elseif ( bp_is_user() ) {
                echo '<a href="' . bp_get_members_directory_permalink() . '">' . x_get_option( 'x_buddypress_members_title' ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
              } else {
                echo $current_before . x_buddypress_get_the_title() . $current_after;
              }
    
            } elseif ( x_is_bbpress() ) {
    
              remove_filter( 'bbp_no_breadcrumb', '__return_true' );
    
              if ( bbp_is_forum_archive() ) {
                echo $current_before . bbp_get_forum_archive_title() . $current_after;
              } else {
                echo bbp_get_breadcrumb();
              }
    
              add_filter( 'bbp_no_breadcrumb', '__return_true' );
    
            } elseif ( is_page() && ! $post_parent ) {
    
              echo $current_before . $page_title . $current_after;
    
            } elseif ( is_page() && $post_parent ) {
    
              $parent_id   = $post_parent;
              $breadcrumbs = array();
    
              if ( is_rtl() ) {
                echo $current_before . $page_title . $current_after . $delimiter;
              }
    
              while ( $parent_id ) {
                $page          = get_page( $parent_id );
                $breadcrumbs[] = '<a href="' . get_permalink( $page->ID ) . '">' . get_the_title( $page->ID ) . '</a>';
                $parent_id     = $page->post_parent;
              }
    
              if ( $is_ltr ) {
                $breadcrumbs = array_reverse( $breadcrumbs );
              }
    
              for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
                echo $breadcrumbs[$i];
                if ( $i != count( $breadcrumbs ) -1 ) echo $delimiter;
              }
    
              if ( $is_ltr ) {
                echo $delimiter . $current_before . $page_title . $current_after;
              }
    
            } elseif ( is_tag() ) {
    
              echo $current_before . single_tag_title( '', false ) . $current_after;
    
            } elseif ( is_author() ) {
    
              GLOBAL $author;
              $userdata = get_userdata( $author );
              echo $current_before . __( 'Posts by ', '__x__' ) . '“' . $userdata->display_name . $current_after . '”';
    
            } elseif ( is_404() ) {
    
              echo $current_before . __( '404 (Page Not Found)', '__x__' ) . $current_after;
    
            } elseif ( is_archive() ) {
    
              if ( x_is_shop() ) {
                echo $current_before . $shop_title . $current_after;
              } else {
                echo $current_before . __( 'Archives ', '__x__' ) . $current_after;
              }
    
            }
    
          echo '</div>';
    
        }
    
      }

    And with the code above, you need to find this lines:

    if ( X_WOOCOMMERCE_IS_ACTIVE ) {
      $shop_url   = x_get_shop_link();
      $shop_title = x_get_option( 'x_' . $stack . '_shop_title' );
      $shop_link  = '<a href="'. $shop_url .'">' . $shop_title . '</a>';
    }

    And you have to replace it with this:

    if ( X_WOOCOMMERCE_IS_ACTIVE ) {
      $shop_url   = home_url().'/cause-new/';
      $shop_title = __( 'Causes New', '__x__' );
      $shop_link  = '<a href="'. $shop_url .'">' . $shop_title . '</a>';
    }

    And to change the link of the return to shop button, you need to insert the following code into your child theme’s functions.php file as well

    function change_return_to_shop_link(){
      return home_url().'/cause-new/';
    }
    add_filter('woocommerce_return_to_shop_redirect', 'change_return_to_shop_link', 50);

    As this is all custom development, regretfully we won’t be able to assist further. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.

    Thank you for you understanding.

    #781014

    bayne
    Participant

    Hi There,

    Firstly, thank you so much for such detailed advice and thorough inspection on my site. I appreciate you guys so much, and I will only be using X Theme from now on 🙂

    I have successfully installed the child theme, and I have made the attempt of adding and editing the code you provided above. For some reason, it doesn’t seem to be picking up the above code on the front-end of the site. I’ve attached a pic for viewing. You can also login, and view the child theme function.php file yourself to see if I have pasted the code properly. I added the provided code under “additional functions,” but didn’t try playing around with it too much after finding it unsuccessful.

    Again, thank you so much for the help!

    #781214

    Rue Nel
    Moderator

    Hello There,

    Thanks for the updates! Sorry there was a typographic error in the code we have provided. It is supposedly this one home_url().'/causes-new/'. We went ahead and edited. This should be resolved now. Both the return to shop button and the breadcrumb is pointing to this page: http://www.your-domain.com/causes-new/

    If you need anything else we can help you with, please let us know.

    #782339

    bayne
    Participant

    Hello there,

    Looks like we’re on the right track, but not quite there. With the current code set up in the child theme, I am not able to edit the page with cornerstone anymore, additionally, the native woocommerce “shop page” still shows up underneath the page I created.

    The page I created (causes new) was set up as a blank – no container | header, footer template layout. The way it looks now has that pesky sidebar that I’m trying to avoid, and, as previously mentioned, has the woocommerce shop page sandwiched underneath.

    I have attached some photos to show you there is no “edit with cornerstone” option at the top, and the current template layout looking like it has a container (even though it is set up without a container)

    Please help 🙁

    #782761

    Rue Nel
    Moderator

    Hello There,

    You need to remove Causes New as the shop page. Setting Causes New as your shop page would make it difficult to edit in Cornerstone as it will be considered as a shop page. I went ahead and remove the assign page for your shop page. Causes New page is now fully a fullwidth page with no container in it. You may continue editing that page in Cornerstone.

    Please let us know how it goes.

    #783148

    bayne
    Participant

    Looks perfect! Thank you so much for the quality assistance! You guys are so great! Just for good measure, Here’s another exclamation!

    #783625

    Rue Nel
    Moderator

    Hello There,

    You’re welcome! We are just glad we were able to help you out.
    If you need anything else we can help you with, don’t hesitate to open another thread.

    Cheers.

    #863471

    cgWerks
    Participant

    WOW! Thank you so much. I’ve been scouring the Web for hours trying to figure this out. Why this kind of flexibility isn’t built right into WooCommerce is beyond me, especially with all the layout type plugins (like grid ones) that support Woo products.

    Sorry to renew the thread again, but I had to say thanks. 🙂

    (This should maybe be written up in a bit more detail and added to the knowledge base, as with the power of both grid extensions, this is a powerful way of building neater WooCommerce stores.)

    #864136

    Rue Nel
    Moderator

    Hello @cgwerks,

    Thanks for updating the thread! I am glad that the solution above works out for you. I would assume that of course you have changed the shop url with your own. We appreciate for letting us know. If you may have other question, please open them up in a separate thread. Our support staff will always be around to respond momentarily.

    Regards.

    #979000

    Daphne D
    Participant

    Hi, I was directed here from my post at: https://community.theme.co/forums/topic/woo-commerce-alternate-page/

    I just wanted to say this thread helped get my Essential Grid store working properly. However, after inserting this to my function.php …

    function change_return_to_shop_link(){
    return home_url().’/cause-new/’;
    }
    add_filter(‘woocommerce_return_to_shop_redirect’, ‘change_return_to_shop_link’, 50);

    I also had to add the following right below it in order to get the Woocommerce “continue shopping” link to work properly on the cart page:

    add_filter( ‘woocommerce_continue_shopping_redirect’, ‘change_return_to_shop_link’, 50);

    Everything works perfectly now!
    Thanks for all the great help!

    #979735

    Friech
    Moderator

    We’re delighted to assist you with this.

    Cheers!

    #984956

    Phil C
    Participant

    Hi “X Team”

    I used the excellent solution outlined here but I think I must be missing something.

    The breadcrumbs redirect to the “Causes-New” page as expected but not the icon that sits just below these links on a given single product page (see screenshot attached). What do I need to do to get that icon to point to the “Causes-New” page.

    Thanks in advance.

    #985415

    Lely
    Moderator

    Hello Phil,

    Please do share us your site URL where you have implemented this so we can check further.

    Always,
    X