Advertisement
cipher87

Change Shop to Store

Feb 19th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.20 KB | None | 0 0
  1. add_action('after_setup_theme','avia_remove_woocommerce_breadcrumb');
  2. function avia_remove_woocommerce_breadcrumb(){
  3.     remove_filter('avia_breadcrumbs_trail','avia_woocommerce_breadcrumb');
  4.     remove_filter('avf_title_args','avia_title_args_woopage');
  5. }
  6.  
  7.  
  8. add_filter('avia_breadcrumbs_trail','avia_custom_woocommerce_breadcrumb', 50, 2);
  9.  
  10. function avia_custom_woocommerce_breadcrumb($trail)
  11. {
  12.     global $avia_config;
  13.  
  14.     if(is_woocommerce())
  15.     {
  16.  
  17.         $home       = $trail[0];
  18.         $last       = array_pop($trail);
  19.         $shop_id    = get_id_by_slug('store');
  20.         $taxonomy   = "product_cat";
  21.  
  22.         // on the shop frontpage simply display the shop name, rather than shop name + "All Products"
  23.         if(is_shop())
  24.         {
  25.             if(!empty($shop_id) && $shop_id  != -1)  $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
  26.             $last = "";
  27.  
  28.             if(is_search())
  29.             {
  30.                 $last = __('Search results for:','avia_framework').' '.esc_attr($_GET['s']);
  31.             }
  32.         }
  33.  
  34.         // on the product page single page modify the breadcrumb to read [home] [if available:parent shop pages] [shop] [if available:parent categories] [category] [title]
  35.         if(is_product())
  36.         {
  37.             //fetch all product categories and search for the ones with parents. if none are avalaible use the first category found
  38.             $product_category = $parent_cat = array();
  39.             $temp_cats = get_the_terms(get_the_ID(), $taxonomy);
  40.  
  41.             if(!empty($temp_cats))
  42.             {
  43.                 foreach($temp_cats as $key => $cat)
  44.                 {
  45.                     if($cat->parent != 0 && !in_array($cat->term_taxonomy_id, $parent_cat))
  46.                     {
  47.                         $product_category[] = $cat;
  48.                         $parent_cat[] = $cat->parent;
  49.                     }
  50.                 }
  51.  
  52.                 //if no categories with parents use the first one
  53.                 if(empty($product_category)) $product_category[] = reset($temp_cats);
  54.  
  55.             }
  56.             //unset the trail and build our own
  57.             unset($trail);
  58.  
  59.             $trail[0] = $home;
  60.             if(!empty($shop_id) && $shop_id  != -1)    $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
  61.             if(!empty($parent_cat)) $trail = array_merge( $trail, avia_breadcrumbs_get_term_parents( $parent_cat[0] , $taxonomy ) );
  62.             if(!empty($product_category)) $trail[] = '<a href="' . get_term_link( $product_category[0]->slug, $taxonomy ) . '" title="' . esc_attr( $product_category[0]->name ) . '">' . $product_category[0]->name . '</a>';
  63.  
  64.         }
  65.  
  66.  
  67.         // add the [shop] trail to category/tag pages: [home] [if available:parent shop pages] [shop] [if available:parent categories] [category/tag]
  68.         if(is_product_category() || is_product_tag())
  69.         {
  70.             if(!empty($shop_id) && $shop_id  != -1)
  71.             {
  72.                 $shop_trail = avia_breadcrumbs_get_parents( $shop_id ) ;
  73.                 array_splice($trail, 1, 0, $shop_trail);
  74.             }
  75.         }
  76.  
  77.         if(is_product_tag())
  78.         {
  79.             $last = __("Tag",'avia_framework').": ".$last;
  80.         }
  81.  
  82.  
  83.         if(!empty($last)) $trail[] = $last;
  84.     }
  85.  
  86.     return $trail;
  87. }
  88.  
  89. add_filter('avf_title_args','avia_title_args_custom_woopage', 10, 4);
  90. function avia_title_args_custom_woopage($args)
  91. {
  92.     if(is_single() && is_product())
  93.     {
  94.         $args['heading'] = "strong";
  95.         $args['title'] = "Store";
  96.     }
  97.  
  98.     return $args;
  99. }
  100.  
  101. function get_id_by_slug($page_slug) {
  102.     $page = get_page_by_path($page_slug);
  103.     if ($page) {
  104.         return $page->ID;
  105.     } else {
  106.         return null;
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement