Advertisement
Guest User

config.php

a guest
Jul 11th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 35.63 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function avia_woocommerce_enabled()
  5. {
  6.     if ( class_exists( 'woocommerce' ) ){ return true; }
  7.     return false;
  8. }
  9.  
  10.  
  11. global $avia_config;
  12.  
  13. //product thumbnails
  14. $avia_config['imgSize']['shop_thumbnail']   = array('width'=>130, 'height'=>85);
  15. $avia_config['imgSize']['shop_catalog']     = array('width'=>450, 'height'=>450);
  16. $avia_config['imgSize']['shop_single']      = array('width'=>450, 'height'=>999, 'crop' => false);
  17. avia_backend_add_thumbnail_size($avia_config);
  18.  
  19. include('admin-options.php');
  20. include('admin-import.php');
  21. include( 'woocommerce-mod-css-dynamic.php');
  22.  
  23. add_theme_support( 'woocommerce' );
  24.  
  25. //check if the plugin is enabled, otherwise stop the script
  26. if(!avia_woocommerce_enabled()) { return false; }
  27.  
  28.  
  29. //register my own styles, remove wootheme stylesheet
  30. if(!is_admin()){
  31.     add_action('init', 'avia_woocommerce_register_assets');
  32. }
  33.  
  34.  
  35.  
  36. function avia_woocommerce_register_assets()
  37. {
  38.     wp_enqueue_style( 'avia-woocommerce-css', AVIA_BASE_URL.'config-woocommerce/woocommerce-mod.css');
  39.  
  40.     if( version_compare( WC()->version, '2.7.0', '<' ) )
  41.     {
  42.         wp_enqueue_script( 'avia-woocommerce-js', AVIA_BASE_URL.'config-woocommerce/woocommerce-mod-v26.js', array('jquery'), 1, true );
  43.     }
  44.     else
  45.     {
  46.         wp_enqueue_script( 'avia-woocommerce-js', AVIA_BASE_URL.'config-woocommerce/woocommerce-mod.js', array('jquery'), 1, true );
  47.     }
  48.  
  49. }
  50.  
  51. global $woocommerce;
  52.  
  53. if(version_compare($woocommerce->version, "2.1", "<"))
  54. {
  55.     define('WOOCOMMERCE_USE_CSS', false);
  56.     $avia_config['woocommerce_version'] = "pre21";
  57. }
  58. else
  59. {
  60.     add_filter( 'woocommerce_enqueue_styles', 'avia_woocommerce_enqueue_styles' );
  61.     function avia_woocommerce_enqueue_styles($styles)
  62.     {
  63.         global $woocommerce, $avia_config;
  64.  
  65.         $avia_config['woocommerce_version'] = $woocommerce->version;
  66.         $styles = array();
  67.         return $styles;
  68.     }
  69. }
  70.  
  71.  
  72. function avia_woocommerce_change_search()
  73. {
  74.     if(avia_get_option('header_search') == 'product')
  75.     {
  76.         echo '<input type="hidden" name="post_type" value="product">';
  77.     }
  78.  
  79. }
  80.  
  81. add_action('avia_frontend_search_form', 'avia_woocommerce_change_search');
  82.  
  83. function avia_woocommerce_change_search_label($label)
  84. {
  85.     if(avia_get_option('header_search') == 'product')
  86.     {
  87.         $label = __('Search for products','avia_framework');
  88.     }
  89.         return $label;
  90. }
  91.  
  92. add_action('avia_frontend_search_form_label', 'avia_woocommerce_change_search_label');
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. ######################################################################
  100. # config
  101. ######################################################################
  102.  
  103. //add avia_framework config defaults
  104.  
  105. $avia_config['shop_overview_column']  = get_option('avia_woocommerce_column_count');  // columns for the overview page
  106. $avia_config['shop_overview_products']= get_option('avia_woocommerce_product_count'); // products for the overview page
  107.  
  108. $avia_config['shop_single_column']   = 4;           // columns for related products and upsells
  109. $avia_config['shop_single_column_items']     = 4;   // number of items for related products and upsells
  110. $avia_config['shop_overview_excerpt'] = false;      // display excerpt
  111.  
  112. if(!$avia_config['shop_overview_column']) $avia_config['shop_overview_column'] = 3;
  113.  
  114.  
  115. ######################################################################
  116. # Create the correct template html structure
  117. ######################################################################
  118.  
  119. //remove woo defaults
  120. remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
  121. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
  122. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
  123. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
  124. remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
  125. remove_action( 'woocommerce_pagination', 'woocommerce_catalog_ordering', 20 );
  126. remove_action( 'woocommerce_pagination', 'woocommerce_pagination', 10 );
  127. remove_action( 'woocommerce_before_single_product', array($woocommerce, 'show_messages'), 10);
  128.  
  129.  
  130.  
  131. //add theme actions && filter
  132. add_action( 'woocommerce_after_shop_loop_item_title', 'avia_woocommerce_overview_excerpt', 10);
  133. add_filter( 'loop_shop_columns', 'avia_woocommerce_loop_columns');
  134. add_filter( 'loop_shop_per_page', 'avia_woocommerce_product_count' );
  135.  
  136. //single page adds
  137. add_action( 'avia_add_to_cart', 'woocommerce_template_single_add_to_cart', 30, 2 );
  138.  
  139.  
  140.  
  141. /*update woocommerce v2*/
  142.  
  143. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); /*remove result count above products*/
  144. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); /*remove woocommerce ordering dropdown*/
  145. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); //remove rating
  146. remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 ); //remove woo pagination
  147.  
  148.  
  149.  
  150. ######################################################################
  151. # FUNCTIONS
  152. ######################################################################
  153.  
  154. function avia_woocommerce_version_check( $version  )
  155. {
  156.     global $woocommerce;
  157.     if( version_compare( $woocommerce->version, $version, ">=" ) ) {
  158.         return true;
  159.     }
  160.  
  161.     return false;
  162. }
  163.  
  164. if(avia_woocommerce_version_check('3.0.0')) // in woocommerce 3.0.0
  165. {
  166.     add_action('woocommerce_product_thumbnails', 'avia_product_gallery_thumbnail_opener', 19);
  167.     add_action('woocommerce_product_thumbnails',  'avia_close_div', 21);
  168. }
  169.  
  170. if(!function_exists('avia_product_gallery_thumbnail_opener'))
  171. {
  172.     function avia_product_gallery_thumbnail_opener()
  173.     {
  174.         echo "<div class='thumbnails'>";
  175.     }
  176. }
  177.  
  178.  
  179.  
  180. #
  181. # removes the default post image from shop overview pages and replaces it with this image
  182. #
  183. add_action( 'woocommerce_before_shop_loop_item_title', 'avia_woocommerce_thumbnail', 10);
  184. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
  185.  
  186.  
  187. function avia_woocommerce_thumbnail($asdf)
  188. {
  189.     global $product, $avia_config;
  190.  
  191.     if(function_exists('wc_get_rating_html'))
  192.     {
  193.         $rating = wc_get_rating_html(  $product->get_average_rating() );
  194.     }
  195.     else
  196.     {
  197.         $rating = $product->get_rating_html(); //get rating
  198.     }
  199.  
  200.     $id = get_the_ID();
  201.     $size = 'shop_catalog';
  202.  
  203.     echo "<div class='thumbnail_container'>";
  204.         echo avia_woocommerce_gallery_first_thumbnail( $id , $size);
  205.         echo get_the_post_thumbnail( $id , $size );
  206.         if(!empty($rating)) echo "<span class='rating_container'>".$rating."</span>";
  207.         if($product->get_type() == 'simple') echo "<span class='cart-loading'></span>";
  208.     echo "</div>";
  209. }
  210.  
  211.  
  212. function avia_woocommerce_gallery_first_thumbnail($id, $size, $id_only = false)
  213. {
  214.     $active_hover = get_post_meta( $id, '_product_hover', true );
  215.  
  216.     if(!empty($active_hover))
  217.     {
  218.         $product_gallery = get_post_meta( $id, '_product_image_gallery', true );
  219.  
  220.         if(!empty($product_gallery))
  221.         {
  222.             $gallery    = explode(',',$product_gallery);
  223.             $image_id   = $gallery[0];
  224.  
  225.             //return id only
  226.             if(!empty($id_only)) return $image_id;
  227.  
  228.             $image      = wp_get_attachment_image( $image_id, $size, false, array( 'class' => "attachment-$size avia-product-hover" ));
  229.  
  230.             //return image
  231.             if(!empty($image)) return $image;
  232.         }
  233.     }
  234. }
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241. #
  242. # add ajax cart / options buttons to the product
  243. #
  244.  
  245. add_action( 'woocommerce_after_shop_loop_item', 'avia_add_cart_button', 6);
  246. function avia_add_cart_button()
  247. {
  248.     global $product;
  249.  
  250.     $product_type = ( method_exists( $product, 'get_type' ) ) ? $product->get_type() : $product->product_type;
  251.     $product_id = ( method_exists( $product, 'get_id' ) ) ? $product->get_id() : $product->id;
  252.  
  253.     if ( $product_type == 'bundle' ){
  254.         $product = new WC_Product_Bundle( $product_id );
  255.     }
  256.  
  257.     $extraClass  = "";
  258.  
  259.     ob_start();
  260.     woocommerce_template_loop_add_to_cart();
  261.     $output = ob_get_clean();
  262.  
  263.     if( $product_type == 'variable' && empty( $output ) )
  264.     {
  265.         $output = "<a class='add_to_cart_button button product_type_variable' href='".get_permalink( $product_id )."'>".__('Select options','avia_framework')."</a>";
  266.     }
  267.  
  268.     if( $product_type == 'simple' )
  269.     {
  270.         $output .= "<a class='button show_details_button' href='".get_permalink( $product_id )."'>".__('Show Details','avia_framework')."</a>";
  271.     }
  272.     else
  273.     {
  274.         $extraClass  = "single_button";
  275.     }
  276.  
  277.     if($output) echo "<div class='avia_cart_buttons $extraClass'><div class='inner_cart_button'>$output</div></div>";
  278. }
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285. #
  286. # wrap products on overview pages into an extra div for improved styling options. adds "product_on_sale" class if prodct is on sale
  287. #
  288.  
  289. add_action( 'woocommerce_before_shop_loop_item', 'avia_shop_overview_extra_div', 5);
  290. function avia_shop_overview_extra_div()
  291. {
  292.     global $product;
  293.     $product_class = $product->is_on_sale() ? "product_on_sale" : "";
  294.  
  295.     echo "<div class='inner_product wrapped_style $product_class'>";
  296. }
  297.  
  298. add_action( 'woocommerce_after_shop_loop_item',  'avia_close_div', 1000);
  299. function avia_close_div()
  300. {
  301.     echo "</div>";
  302. }
  303.  
  304.  
  305. #
  306. # wrap product titles and sale number on overview pages into an extra div for improved styling options
  307. #
  308.  
  309. add_action( 'woocommerce_before_shop_loop_item_title', 'avia_shop_overview_extra_header_div', 20);
  310. function avia_shop_overview_extra_header_div()
  311. {
  312.     echo "<div class='inner_product_header'>";
  313. }
  314.  
  315. add_action( 'woocommerce_after_shop_loop_item_title',  'avia_close_div', 1000);
  316.  
  317.  
  318. #
  319. # remove on sale badge from usual location and add it to the bottom of the product
  320. #
  321. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10);
  322. add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10);
  323.  
  324.  
  325. #
  326. # create the shop navigation with account links, as well as cart and checkout, called as fallback function by the wp_nav_menu function in header.php
  327. #
  328. function avia_shop_nav($args)
  329. {
  330.     $output = "";
  331.     $url = avia_collect_shop_urls();
  332.  
  333.     $output .= "<ul>";
  334.  
  335.     if( is_user_logged_in() )
  336.     {
  337.         global $woocommerce, $wp;
  338.  
  339.  
  340.         $current = $sub1 = $sub2 = $sub3 = "";
  341.         if(is_account_page()) $current = "current-menu-item";
  342.         if(is_page(get_option('woocommerce_change_password_page_id'))) $sub1 = "current-menu-item";
  343.         if(is_page(get_option('woocommerce_edit_address_page_id'))) $sub2 = "current-menu-item";
  344.         if(is_page(get_option('woocommerce_view_order_page_id'))) $sub3 = "current-menu-item";
  345.  
  346.  
  347.         //woo version 2.1+ determination of page
  348.         if ( isset( $wp->query_vars['edit-account'] ) ) { $sub1 = "current-menu-item"; }
  349.         if ( isset( $wp->query_vars['edit-address'] ) ) { $sub2 = "current-menu-item"; }
  350.         if ( isset( $wp->query_vars['view-order'] ) )   { $sub3 = "current-menu-item"; }
  351.  
  352.  
  353.  
  354.  
  355.         $output .= "<li class='$current account_overview_link'><a href='".$url['account_overview']."'>".__('My Account', 'avia_framework')."</a>";
  356.             $output .= "<ul>";
  357.             $output .= "<li class='$sub1 account_change_pw_link'><a href='".$url['account_change_pw']."'>".__('Change Password', 'avia_framework')."</a></li>";
  358.             $output .= "<li class='$sub2 account_edit_adress_link'><a href='".$url['account_edit_adress']."'>".__('Edit Address', 'avia_framework')."</a></li>";
  359.             $output .= "<li class='$sub3 account_view_order_link'><a href='".$url['account_view_order']."'>".__('View Order', 'avia_framework')."</a></li>";
  360.             $output .= "</ul>";
  361.         $output .= "</li>";
  362.         $output .= "<li class='account_logout_link'><a href='".$url['logout']."'>".__('Log Out', 'avia_framework')."</a></li>";
  363.     }
  364.     else
  365.     {
  366.         $sub1 = $sub2 = "";
  367.         if(is_page(get_option('woocommerce_myaccount_page_id')))
  368.         {
  369.             if(isset($_GET['account_visible']) && $_GET['account_visible'] == 'register') $sub1 = "current-menu-item";
  370.             if(isset($_GET['account_visible']) && $_GET['account_visible'] == 'login') $sub2 = "current-menu-item";
  371.         }
  372.  
  373.         $url_param = strpos($url['account_overview'], '?') === false ? "?" : "&";
  374.  
  375.         if (get_option('woocommerce_enable_myaccount_registration') =='yes')
  376.         {
  377.             $output .= "<li class='register_link $sub1'><a href='".$url['account_overview'].$url_param."account_visible=register'>".__('Register', 'avia_framework')."</a></li>";
  378.         }
  379.  
  380.         $output .= "<li class='login_link $sub2'><a href='".$url['account_overview'].$url_param."account_visible=login'>".__('Log In', 'avia_framework')."</a></li>";
  381.     }
  382.  
  383.     $output .= "</ul>";
  384.  
  385.     if($args['echo'] == true)
  386.     {
  387.         echo $output;
  388.     }
  389.     else
  390.     {
  391.         return $output;
  392.     }
  393. }
  394.  
  395.  
  396. #
  397. # helper function that collects all the necessary urls for the shop navigation
  398. #
  399.  
  400. function avia_collect_shop_urls()
  401. {
  402.     global $woocommerce, $avia_config;
  403.  
  404.     $url['cart']                = $woocommerce->cart->get_cart_url();
  405.     $url['checkout']            = $woocommerce->cart->get_checkout_url();
  406.     $url['logout']              = wp_logout_url(home_url('/'));
  407.     $url['account_overview']    = get_permalink(get_option('woocommerce_myaccount_page_id'));
  408.  
  409.     if($avia_config['woocommerce_version'] == "pre21")
  410.     {
  411.         $url['account_edit_adress'] = get_permalink(get_option('woocommerce_edit_address_page_id'));
  412.         $url['account_view_order']  = get_permalink(get_option('woocommerce_view_order_page_id'));
  413.         $url['account_change_pw']   = get_permalink(get_option('woocommerce_change_password_page_id'));
  414.     }
  415.     else
  416.     {
  417.         $order = new WC_Order(false);
  418.         $url['account_edit_adress'] = wc_get_endpoint_url( 'edit-address', '', get_permalink( wc_get_page_id( 'myaccount' ) ) );
  419.         $url['account_view_order']  = $order->get_view_order_url();
  420.         $url['account_change_pw']   = wc_customer_edit_account_url();
  421.     }
  422.  
  423.     return $url;
  424. }
  425.  
  426.  
  427.  
  428.  
  429. #
  430. # check which page is displayed and if the automativ sidebar menu for subpages should be prevented
  431. #
  432. add_filter( 'avia_sidebar_menu_filter', 'avia_woocommerce_sidebar_filter');
  433.  
  434. function avia_woocommerce_sidebar_filter($menu)
  435. {
  436.     $id = avia_get_the_ID();
  437.     if(is_cart() || is_checkout() || get_option('woocommerce_thanks_page_id') == $id){$menu = "";}
  438.     return $menu;
  439. }
  440.  
  441.  
  442. function avia_add_to_cart($post, $product )
  443. {
  444.     $product_type = ( method_exists( $product, 'get_type' ) ) ? $product->get_type() : $product->product_type;
  445.  
  446.     echo "<div class='avia_cart avia_cart_". $product_type ."'>";
  447.     do_action( 'avia_add_to_cart', $post, $product );
  448.     echo "</div>";
  449. }
  450.  
  451.  
  452.  
  453. #
  454. # replace thumbnail image size with full size image on single pages
  455. #
  456. /*
  457.  
  458. add_filter( 'single_product_small_thumbnail_size', 'avia_woocommerce_thumb_size');
  459.  
  460. function avia_woocommerce_thumb_size()
  461. {
  462.     return 'shop_single';
  463. }
  464. */
  465.  
  466.  
  467.  
  468.  
  469. #
  470. # if we are viewing a woocommerce page modify the breadcrumb nav
  471. #
  472.  
  473. if(!function_exists('avia_woocommerce_breadcrumb'))
  474. {
  475.     add_filter('avia_breadcrumbs_trail','avia_woocommerce_breadcrumb');
  476.  
  477.     function avia_woocommerce_breadcrumb($trail)
  478.     {
  479.         global $avia_config;
  480.  
  481.         if(is_woocommerce())
  482.         {
  483.  
  484.             $home       = $trail[0];
  485.             $last       = array_pop($trail);
  486.             $shop_id    = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
  487.             $taxonomy   = "product_cat";
  488.  
  489.             // on the shop frontpage simply display the shop name, rather than shop name + "All Products"
  490.             if(is_shop())
  491.             {
  492.                 if(!empty($shop_id) && $shop_id  != -1)  $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
  493.                 $last = "";
  494.  
  495.                 if(is_search())
  496.                 {
  497.                     $last = __('Search results for: ','avia_framework').esc_attr($_GET['s']);
  498.                 }
  499.             }
  500.  
  501.             // on the product page single page modify the breadcrumb to read [home] [if available:parent shop pages] [shop] [if available:parent categories] [category] [title]
  502.             if(is_product())
  503.             {
  504.                 //fetch all product categories and search for the ones with parents. if none are avalaible use the first category found
  505.                 $product_category = $parent_cat = array();
  506.                 $temp_cats = get_the_terms(get_the_ID(), $taxonomy);
  507.  
  508.                 if(!empty($temp_cats))
  509.                 {
  510.                     foreach($temp_cats as $key => $cat)
  511.                     {
  512.                         if($cat->parent != 0 && !in_array($cat->term_taxonomy_id, $parent_cat))
  513.                         {
  514.                             $product_category[] = $cat;
  515.                             $parent_cat[] = $cat->parent;
  516.                         }
  517.                     }
  518.  
  519.                     //if no categories with parents use the first one
  520.                     if(empty($product_category)) $product_category[] = reset($temp_cats);
  521.  
  522.                 }
  523.                 //unset the trail and build our own
  524.                 unset($trail);
  525.  
  526.                 $trail[0] = $home;
  527.                 if(!empty($shop_id) && $shop_id  != -1)    $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
  528.                 if(!empty($parent_cat)) $trail = array_merge( $trail, avia_breadcrumbs_get_term_parents( $parent_cat[0] , $taxonomy ) );
  529.                 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>';
  530.  
  531.             }
  532.  
  533.  
  534.             // add the [shop] trail to category/tag pages: [home] [if available:parent shop pages] [shop] [if available:parent categories] [category/tag]
  535.             if(is_product_category() || is_product_tag())
  536.             {
  537.                 if(!empty($shop_id) && $shop_id  != -1)
  538.                 {
  539.                     $shop_trail = avia_breadcrumbs_get_parents( $shop_id ) ;
  540.                     array_splice($trail, 1, 0, $shop_trail);
  541.                 }
  542.             }
  543.  
  544.             if(is_product_tag())
  545.             {
  546.                 $last = __("Tag",'avia_framework').": ".$last;
  547.             }
  548.  
  549.  
  550.             if(!empty($last)) $trail[] = $last;
  551.         }
  552.  
  553.         return $trail;
  554.     }
  555.  
  556. }
  557.  
  558.  
  559.  
  560. #
  561. # creates the avia framework container arround the shop pages
  562. #
  563. add_action( 'woocommerce_before_main_content', 'avia_woocommerce_before_main_content', 10);
  564.  
  565.  
  566. function avia_woocommerce_before_main_content()
  567. {
  568.     global $avia_config;
  569.  
  570.     if(!isset($avia_config['shop_overview_column'])) $avia_config['shop_overview_column'] = "auto";
  571.     if($new = avia_post_meta( get_option('woocommerce_shop_page_id'), 'layout'))
  572.     {
  573.          //split up result
  574.          $results = explode(' : ', $new);
  575.          foreach($results as $result)
  576.          {
  577.             $result = explode('|', $result);
  578.             $avia_config[$result[0]] = $result[1];
  579.          }
  580.  
  581.          $avia_config['layout'] = apply_filters('avia_layout_filter',  $avia_config['layout']);
  582.     }
  583.  
  584.     $title_args = array();
  585.  
  586.     if(is_woocommerce())
  587.     {
  588.         $t_link = "";
  589.  
  590.         if(is_shop()) $title  = get_option('woocommerce_shop_page_title');
  591.  
  592.         $shop_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
  593.         if($shop_id && $shop_id != -1)
  594.         {
  595.             if(empty($title)) $title = get_the_title($shop_id);
  596.             $t_link = get_permalink($shop_id);
  597.         }
  598.  
  599.         if(!$title) $title  = __("Shop",'avia_framework');
  600.  
  601.         if(is_product_category() || is_product_tag())
  602.         {
  603.             global $wp_query;
  604.             $tax = $wp_query->get_queried_object();
  605.             $title = $tax->name;
  606.             $t_link = '';
  607.         }
  608.  
  609.         $title_args = array('title' => $title, 'link' => $t_link);
  610.     }
  611.  
  612.     echo avia_title($title_args);
  613.  
  614.     echo "<div class='container_wrap main_color ".avia_layout_class( 'main' , false )." template-shop shop_columns_".$avia_config['shop_overview_column']."'>";
  615.  
  616.         echo "<div class='container'>";
  617.  
  618.         if(!is_singular()) { $avia_config['overview'] = true; }
  619. }
  620.  
  621. #
  622. # closes the avia framework container arround the shop pages
  623. #
  624.  
  625. add_action( 'woocommerce_after_main_content', 'avia_woocommerce_after_main_content', 10);
  626. function avia_woocommerce_after_main_content()
  627. {
  628.     global $avia_config;
  629.     $avia_config['currently_viewing'] = "shop";
  630.  
  631.             //reset all previous queries
  632.             wp_reset_query();
  633.  
  634.             //get the sidebar
  635.             if(!is_singular())
  636.             get_sidebar();
  637.  
  638.         echo "</div>"; // end container
  639.     echo "</div>"; // end tempate-shop content
  640. }
  641.  
  642.  
  643.  
  644.  
  645. #
  646. # wrap an empty product search into extra div
  647. #
  648. add_action( 'woocommerce_before_main_content', 'avia_woocommerce_404_search', 9111);
  649. function avia_woocommerce_404_search()
  650. {
  651.     global $wp_query;
  652.  
  653.     if( (is_search() || is_archive()) && empty($wp_query->found_posts) )
  654.     {
  655.         echo "<div class='template-page template-search template-search-none content ".avia_layout_class( 'content', false )." units'>";
  656.         echo "<div class='entry entry-content' id='search-fail'>";
  657.               get_template_part('includes/error404');
  658.         echo "</div>";
  659.     }
  660. }
  661.  
  662. add_action( 'woocommerce_after_main_content', 'avia_woocommerce_404_search_close', 1);
  663. function avia_woocommerce_404_search_close()
  664. {
  665.     global $wp_query;
  666.     if( is_search() && empty($wp_query->found_posts) ){ echo "</div>";}
  667. }
  668.  
  669.  
  670.  
  671.  
  672. #
  673. # modifies the class of a page so we can display single login and single register
  674. #
  675. add_filter( 'avia_layout_class_filter_main', 'avia_register_login_class');
  676.  
  677. function avia_register_login_class($layout)
  678. {
  679.     if(isset($_GET['account_visible']))
  680.     {
  681.         if($_GET['account_visible'] == 'register') $layout .= " template-register";
  682.         if($_GET['account_visible'] == 'login') $layout .= " template-login";
  683.     }
  684.  
  685.     return $layout;
  686. }
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694. #
  695. # creates the avia framework content container arround the shop loop
  696. #
  697. add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_before_shop_loop', 1);
  698.  
  699. function avia_woocommerce_before_shop_loop()
  700. {
  701.  
  702.     global $avia_config;
  703.     if(isset($avia_config['dynamic_template'])) return;
  704.     echo "<div class='template-shop content ".avia_layout_class( 'content' , false)." units'>";
  705.  
  706. }
  707.  
  708. #
  709. # closes the avia framework content container arround the shop loop
  710. #
  711. add_action( 'woocommerce_after_shop_loop', 'avia_woocommerce_after_shop_loop', 10);
  712.  
  713. function avia_woocommerce_after_shop_loop()
  714. {
  715.             global $avia_config;
  716.             if(isset($avia_config['dynamic_template'])) return;
  717.             if(isset($avia_config['overview'] )) echo avia_pagination();
  718.             echo "</div>"; //end content
  719. }
  720.  
  721.  
  722.  
  723. #
  724. # echo the excerpt
  725. #
  726. function avia_woocommerce_overview_excerpt()
  727. {
  728.     global $avia_config;
  729.  
  730.     if(!empty($avia_config['shop_overview_excerpt']))
  731.     {
  732.         echo "<div class='product_excerpt'>";
  733.         the_excerpt();
  734.         echo "</div>";
  735.     }
  736. }
  737.  
  738.  
  739.  
  740. #
  741. # creates the preview images based on page/category image
  742. #
  743. remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
  744. remove_action( 'woocommerce_product_archive_description', 'woocommerce_product_archive_description', 10 );
  745.  
  746. add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_overview_banner_image', 10);
  747. add_action( 'woocommerce_before_shop_loop', 'woocommerce_taxonomy_archive_description', 11 );
  748. //add_action( 'woocommerce_before_shop_loop', 'woocommerce_product_archive_description', 12 ); //causes warning
  749.  
  750.  
  751. function avia_woocommerce_overview_banner_image()
  752. {
  753.     global $avia_config;
  754.     if(avia_is_dynamic_template() || is_paged() || is_search() ) return false;
  755.  
  756.     $image_size = "featured_small";
  757.  
  758.     if(is_shop())
  759.     {
  760.         $shop_id    = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
  761.         if($shop_id != -1)
  762.         {
  763.             $slider = new avia_slideshow($shop_id);
  764.             $slider -> setImageSize($image_size);
  765.             echo $slider->display();
  766.         }
  767.     }
  768.  
  769.     if(is_product_category())
  770.     {
  771.         global $wp_query;
  772.         $image  = "";
  773.         if(isset($wp_query->query_vars['taxonomy']))
  774.         {
  775.             $term           = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']);
  776.  
  777.             if(!empty($term->term_id))
  778.             {
  779.                 $attachment_id  = get_woocommerce_term_meta($term->term_id, 'thumbnail_id');
  780.  
  781.                 if(!empty($attachment_id))
  782.                 {
  783.                     $image = wp_get_attachment_image( $attachment_id, $image_size, false, array('class'=>'category_thumb'));
  784.                     if($image) echo '<div class="slideshow_container  slide_container_big"><ul class="slideshow fade_slider preloading"><li>'.$image.'</li></ul></div>';
  785.                 }
  786.             }
  787.         }
  788.     }
  789.  
  790. }
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798. #
  799. # creates the title + description for overview pages
  800. #
  801. function avia_woocommerce_advanced_title()
  802. {
  803.     global $wp_query;
  804.     $titleClass     = "";
  805.     $image          = "";
  806.  
  807.  
  808.     if(!empty($attachment_id))
  809.     {
  810.         $titleClass .= "title_container_image ";
  811.         $image      = wp_get_attachment_image( $attachment_id, 'thumbnail', false, array('class'=>'category_thumb'));
  812.     }
  813.  
  814.     echo "<div class='extralight-border title_container shop_title_container $titleClass'>";
  815.     //echo avia_breadcrumbs();
  816.     woocommerce_catalog_ordering();
  817.     echo $image;
  818. }
  819.  
  820.  
  821. function avia_woocommerce_cart_dropdown()
  822. {
  823.     global $woocommerce;
  824.     $cart_subtotal = $woocommerce->cart->get_cart_subtotal();
  825.     $link = $woocommerce->cart->get_cart_url();
  826.  
  827.  
  828.     $output = "";
  829.     $output .= "<ul class = 'cart_dropdown' data-success='".__('Product added', 'avia_framework')."'><li class='cart_dropdown_first'>";
  830.     $output .= "<a class='cart_dropdown_link' href='".$link."'>".__('Cart', 'avia_framework')." - </a><span class='cart_subtotal'>".$cart_subtotal."</span>";
  831.     $output .= "<div class='dropdown_widget dropdown_widget_cart'>";
  832.     $output .= '<div class="widget_shopping_cart_content"><p class="avia_empty_cart">'.__('No products in your shopping cart.','avia_framework').'</p></div>';
  833.     $output .= "</div>";
  834.     $output .= "</li></ul>";
  835.  
  836.     return $output;
  837. }
  838.  
  839.  
  840.  
  841. #
  842. # modify shop overview column count
  843. #
  844. function avia_woocommerce_loop_columns()
  845. {
  846.     global $avia_config;
  847.     return $avia_config['shop_overview_column'];
  848. }
  849.  
  850.  
  851. #
  852. # modify shop overview product count
  853. #
  854.  
  855. function avia_woocommerce_product_count()
  856. {
  857.     global $avia_config;
  858.     return $avia_config['shop_overview_products'];
  859. }
  860.  
  861.  
  862.  
  863. #
  864. # display tabs and related items within the summary wrapper
  865. #
  866. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
  867. add_action(    'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 1 );
  868.  
  869.  
  870.  
  871. #
  872. # display upsells and related products within dedicated div with different column and number of products
  873. #
  874. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products',20);
  875. remove_action( 'woocommerce_after_single_product', 'woocommerce_output_related_products',10);
  876. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_output_related_products', 20);
  877.  
  878. function avia_woocommerce_output_related_products()
  879. {
  880.     global $avia_config;
  881.     $output = "";
  882.  
  883.     ob_start();
  884.     woocommerce_related_products(array('posts_per_page'=>$avia_config['shop_single_column_items'], 'columns'=>$avia_config['shop_single_column'])); // X products, X columns
  885.     $content = ob_get_clean();
  886.     if($content)
  887.     {
  888.         $output .= "<div class='product_column product_column_".$avia_config['shop_single_column']."'>";
  889.         //$output .= "<h3>".(__('Related Products', 'avia_framework'))."</h3>";
  890.         $output .= $content;
  891.         $output .= "</div>";
  892.     }
  893.  
  894.     $avia_config['woo_related'] = $output;
  895.  
  896. }
  897.  
  898. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
  899. remove_action( 'woocommerce_after_single_product', 'woocommerce_upsell_display',10);
  900. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_output_upsells', 21); // needs to be called after the "related product" function to inherit columns and product count
  901.  
  902. function avia_woocommerce_output_upsells()
  903. {
  904.     global $avia_config;
  905.  
  906.     $output = "";
  907.  
  908.     ob_start();
  909.     woocommerce_upsell_display($avia_config['shop_single_column_items'],$avia_config['shop_single_column']); // 4 products, 4 columns
  910.     $content = ob_get_clean();
  911.     if($content)
  912.     {
  913.         $output .= "<div class='product_column product_column_".$avia_config['shop_single_column']."'>";
  914.         //$output .= "<h3>".(__('You may also like', 'avia_framework'))."</h3>";
  915.         $output .= $content;
  916.         $output .= "</div>";
  917.     }
  918.  
  919.     $avia_config['woo_upsells'] = $output;
  920.  
  921. }
  922.  
  923. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_display_output_upsells', 30); //display the related products and upsells
  924.  
  925. function avia_woocommerce_display_output_upsells()
  926. {
  927.     global $avia_config;
  928.  
  929.     echo $avia_config['woo_upsells'];
  930.     echo $avia_config['woo_related'];
  931. }
  932.  
  933.  
  934.  
  935. #
  936. # wrap single product image in an extra div
  937. #
  938. add_action( 'woocommerce_before_single_product_summary', 'avia_add_image_div', 2);
  939. add_action( 'woocommerce_before_single_product_summary',  'avia_close_image_div', 20);
  940. function avia_add_image_div()
  941. {
  942.     echo "<div class='four units single-product-main-image alpha'>";
  943. }
  944.  
  945. function avia_close_image_div()
  946. {
  947.     global $avia_config;
  948.     $avia_config['currently_viewing'] = "shop_single";
  949.     get_sidebar();
  950.     echo "</div>";
  951. }
  952.  
  953.  
  954. #
  955. # wrap single product summary in an extra div
  956. #
  957. add_action( 'woocommerce_before_single_product_summary', 'avia_add_summary_div', 25);
  958. add_action( 'woocommerce_after_single_product_summary',  'avia_close_div', 3);
  959. function avia_add_summary_div()
  960. {
  961.     echo "<div class='eight units single-product-summary'>";
  962. }
  963.  
  964.  
  965. //remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973. #
  974. # displays a front end interface for modifying the shoplist query parameters like sorting order, product count etc
  975. #
  976. if(!function_exists('avia_woocommerce_frontend_search_params'))
  977. {
  978.     add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_frontend_search_params', 20);
  979.  
  980.     function avia_woocommerce_frontend_search_params()
  981.     {
  982.         global $avia_config;
  983.  
  984.         if(!empty($avia_config['woocommerce']['disable_sorting_options'])) return false;
  985.  
  986.         $product_order['default']   = __("Default Order",'avia_framework');
  987.         $product_order['title']     = __("Name",'avia_framework');
  988.         $product_order['price']     = __("Price",'avia_framework');
  989.         $product_order['date']      = __("Date",'avia_framework');
  990.  
  991.         $product_sort['asc']        = __("Click to order products ascending",  'avia_framework');
  992.         $product_sort['desc']       = __("Click to order products descending",  'avia_framework');
  993.  
  994.         $per_page_string            = __("Products per page",'avia_framework');
  995.  
  996.  
  997.         $per_page                   = get_option('avia_woocommerce_product_count');
  998.         if(!$per_page) $per_page    = get_option('posts_per_page');
  999.         if(!empty($avia_config['woocommerce']['default_posts_per_page'])) $per_page = $avia_config['woocommerce']['default_posts_per_page'];
  1000.  
  1001.  
  1002.         parse_str($_SERVER['QUERY_STRING'], $params);
  1003.  
  1004.         $po_key = !empty($avia_config['woocommerce']['product_order']) ? $avia_config['woocommerce']['product_order'] : 'default';
  1005.         $ps_key = !empty($avia_config['woocommerce']['product_sort'])  ? $avia_config['woocommerce']['product_sort'] : 'asc';
  1006.         $pc_key = !empty($avia_config['woocommerce']['product_count']) ? $avia_config['woocommerce']['product_count'] : $per_page;
  1007.  
  1008.         $ps_key = strtolower($ps_key);
  1009.  
  1010.         //generate markup
  1011.         $output  = "";
  1012.         $output .= "<div class='product-sorting'>";
  1013.         $output .= "    <ul class='sort-param sort-param-order'>";
  1014.         $output .= "        <li><span class='currently-selected'>".__("Sort by",'avia_framework')." <strong>".$product_order[$po_key]."</strong></span>";
  1015.         $output .= "        <ul>";
  1016.         $output .= "        <li".avia_woo_active_class($po_key, 'default')."><a href='".avia_woo_build_query_string($params, 'product_order', 'default')."'>    <span class='avia-bullet'></span>".$product_order['default']."</a></li>";
  1017.         $output .= "        <li".avia_woo_active_class($po_key, 'title')."><a href='".avia_woo_build_query_string($params, 'product_order', 'title')."'>    <span class='avia-bullet'></span>".$product_order['title']."</a></li>";
  1018.         $output .= "        <li".avia_woo_active_class($po_key, 'price')."><a href='".avia_woo_build_query_string($params, 'product_order', 'price')."'>    <span class='avia-bullet'></span>".$product_order['price']."</a></li>";
  1019.         $output .= "        <li".avia_woo_active_class($po_key, 'date')."><a href='".avia_woo_build_query_string($params, 'product_order', 'date')."'>  <span class='avia-bullet'></span>".$product_order['date']."</a></li>";
  1020.         $output .= "        </ul>";
  1021.         $output .= "        </li>";
  1022.         $output .= "    </ul>";
  1023.  
  1024.         $output .= "    <ul class='sort-param sort-param-sort'>";
  1025.         $output .= "        <li>";
  1026.         if($ps_key == 'desc')   $output .= "            <a title='".$product_sort['asc']."' class='sort-param-asc'  href='".avia_woo_build_query_string($params, 'product_sort', 'asc')."'>".$product_sort['desc']."</a>";
  1027.         if($ps_key == 'asc')    $output .= "            <a title='".$product_sort['desc']."' class='sort-param-desc' href='".avia_woo_build_query_string($params, 'product_sort', 'desc')."'>".$product_sort['asc']."</a>";
  1028.         $output .= "        </li>";
  1029.         $output .= "    </ul>";
  1030.  
  1031.         $output .= "    <ul class='sort-param sort-param-count'>";
  1032.         $output .= "        <li><span class='currently-selected'>".__("Display",'avia_framework')." <strong>".$pc_key." ".$per_page_string."</strong></span>";
  1033.         $output .= "        <ul>";
  1034.         $output .= "        <li".avia_woo_active_class($pc_key, $per_page).">  <a href='".avia_woo_build_query_string($params, 'product_count', $per_page)."'>      <span class='avia-bullet'></span>".$per_page." ".$per_page_string."</a></li>";
  1035.         $output .= "        <li".avia_woo_active_class($pc_key, $per_page*2)."><a href='".avia_woo_build_query_string($params, 'product_count', $per_page * 2)."'>  <span class='avia-bullet'></span>".($per_page * 2)." ".$per_page_string."</a></li>";
  1036.         $output .= "        <li".avia_woo_active_class($pc_key, $per_page*3)."><a href='".avia_woo_build_query_string($params, 'product_count', $per_page * 3)."'>  <span class='avia-bullet'></span>".($per_page * 3)." ".$per_page_string."</a></li>";
  1037.         $output .= "        </ul>";
  1038.         $output .= "        </li>";
  1039.         $output .= "    </ul>";
  1040.  
  1041.  
  1042.  
  1043.         $output .= "</div>";
  1044.         echo $output;
  1045.     }
  1046. }
  1047.  
  1048. //helper function to create the active list class
  1049. if(!function_exists('avia_woo_active_class'))
  1050. {
  1051.     function avia_woo_active_class($key1, $key2)
  1052.     {
  1053.         if($key1 == $key2) return " class='current-param'";
  1054.     }
  1055. }
  1056.  
  1057.  
  1058. //helper function to build the query strings for the catalog ordering menu
  1059. if(!function_exists('avia_woo_build_query_string'))
  1060. {
  1061.     function avia_woo_build_query_string($params = array(), $overwrite_key, $overwrite_value)
  1062.     {
  1063.         $params[$overwrite_key] = $overwrite_value;
  1064.         $paged = (array_key_exists('product_count', $params)) ? 'paged=1&' : '';
  1065.         return "?" . $paged . http_build_query($params);
  1066.     }
  1067. }
  1068.  
  1069. //function that actually overwrites the query parameters
  1070. if(!function_exists('avia_woocommerce_overwrite_catalog_ordering'))
  1071. {
  1072.     add_action( 'woocommerce_get_catalog_ordering_args', 'avia_woocommerce_overwrite_catalog_ordering', 20);
  1073.  
  1074.     function avia_woocommerce_overwrite_catalog_ordering($args)
  1075.     {
  1076.  
  1077.         global $avia_config;
  1078.  
  1079.         //check the folllowing get parameters and session vars. if they are set overwrite the defaults
  1080.         $check = array('product_order', 'product_count', 'product_sort');
  1081.         if(empty($avia_config['woocommerce'])) $avia_config['woocommerce'] = array();
  1082.  
  1083.         foreach($check as $key)
  1084.         {
  1085.             if(isset($_GET[$key]) ) $_SESSION['avia_woocommerce'][$key] = esc_attr($_GET[$key]);
  1086.             if(isset($_SESSION['avia_woocommerce'][$key]) ) $avia_config['woocommerce'][$key] = $_SESSION['avia_woocommerce'][$key];
  1087.         }
  1088.  
  1089.  
  1090.         // is user wants to use new product order remove the old sorting parameter
  1091.         if(isset($_GET['product_order']) && !isset($_GET['product_sort']) && isset($_SESSION['avia_woocommerce']['product_sort']))
  1092.         {
  1093.             unset($_SESSION['avia_woocommerce']['product_sort'], $avia_config['woocommerce']['product_sort']);
  1094.         }
  1095.  
  1096.         extract($avia_config['woocommerce']);
  1097.  
  1098.         // set the product order
  1099.         if(!empty($product_order))
  1100.         {
  1101.             switch ( $product_order ) {
  1102.                 case 'date'  : $orderby = 'date'; $order = 'desc'; $meta_key = '';  break;
  1103.                 case 'price' : $orderby = 'meta_value_num'; $order = 'asc'; $meta_key = '_price'; break;
  1104.                 case 'title' : $orderby = 'title'; $order = 'asc'; $meta_key = ''; break;
  1105.                 case 'default':
  1106.                 default :      $orderby = 'menu_order title'; $order = 'asc'; $meta_key = ''; break;
  1107.             }
  1108.         }
  1109.  
  1110.         // set the product count
  1111.         if(!empty($product_count) && is_numeric($product_count))
  1112.         {
  1113.             $avia_config['shop_overview_products'] = (int) $product_count;
  1114.         }
  1115.  
  1116.         //set the product sorting
  1117.         if(!empty($product_sort))
  1118.         {
  1119.             switch ( $product_sort ) {
  1120.                 case 'desc' : $order = 'desc'; break;
  1121.                 case 'asc' : $order = 'asc'; break;
  1122.                 default : $order = 'asc'; break;
  1123.             }
  1124.         }
  1125.  
  1126.  
  1127.         if(isset($orderby)) $args['orderby'] = $orderby;
  1128.         if(isset($order))   $args['order'] = $order;
  1129.         if (!empty($meta_key))
  1130.         {
  1131.             $args['meta_key'] = $meta_key;
  1132.         }
  1133.  
  1134.  
  1135.         $avia_config['woocommerce']['product_sort'] = $args['order'];
  1136.         return $args;
  1137.     }
  1138.  
  1139.  
  1140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement