Guest User

Untitled

a guest
Mar 2nd, 2015
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.37 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'=>120, 'height'=>120);
  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.  
  18. avia_backend_add_thumbnail_size($avia_config);
  19.  
  20. include('admin-options.php');
  21. include('admin-import.php');
  22. include( 'woocommerce-mod-css-dynamic.php');
  23.  
  24. add_theme_support( 'woocommerce' );
  25.  
  26. //check if the plugin is enabled, otherwise stop the script
  27. if(!avia_woocommerce_enabled()) { return false; }
  28.  
  29.  
  30. //register my own styles, remove wootheme stylesheet
  31. if(!is_admin()){
  32. add_action('init', 'avia_woocommerce_register_assets');
  33. }
  34.  
  35.  
  36.  
  37. function avia_woocommerce_register_assets()
  38. {
  39. wp_enqueue_style( 'avia-woocommerce-css', AVIA_BASE_URL.'config-woocommerce/woocommerce-mod.css');
  40. wp_enqueue_script( 'avia-woocommerce-js', AVIA_BASE_URL.'config-woocommerce/woocommerce-mod.js', array('jquery'), 1, true);
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. global $woocommerce;
  48.  
  49. if(version_compare($woocommerce->version, "2.1", "<"))
  50. {
  51. define('WOOCOMMERCE_USE_CSS', false);
  52. }
  53. else
  54. {
  55. add_filter( 'woocommerce_enqueue_styles', 'avia_woocommerce_enqueue_styles' );
  56. function avia_woocommerce_enqueue_styles($styles)
  57. {
  58. $styles = array();
  59. return $styles;
  60. }
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. ######################################################################
  74. # config
  75. ######################################################################
  76.  
  77. //add avia_framework config defaults
  78.  
  79. $avia_config['shop_overview_column'] = get_option('avia_woocommerce_column_count'); // columns for the overview page
  80. $avia_config['shop_overview_products']= get_option('avia_woocommerce_product_count'); // products for the overview page
  81.  
  82. $avia_config['shop_single_column'] = 4; // columns for related products and upsells
  83. $avia_config['shop_single_column_items'] = 4; // number of items for related products and upsells
  84. $avia_config['shop_overview_excerpt'] = false; // display excerpt
  85.  
  86. if(!$avia_config['shop_overview_column']) $avia_config['shop_overview_column'] = 3;
  87.  
  88.  
  89. ######################################################################
  90. # Create the correct template html structure
  91. ######################################################################
  92.  
  93. //remove woo defaults
  94. remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
  95. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
  96. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
  97. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
  98. remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
  99. remove_action( 'woocommerce_pagination', 'woocommerce_catalog_ordering', 20 );
  100. remove_action( 'woocommerce_pagination', 'woocommerce_pagination', 10 );
  101. remove_action( 'woocommerce_before_single_product', array($woocommerce, 'show_messages'), 10);
  102.  
  103.  
  104.  
  105. //add theme actions && filter
  106. add_action( 'woocommerce_after_shop_loop_item_title', 'avia_woocommerce_overview_excerpt', 10);
  107. add_filter( 'loop_shop_columns', 'avia_woocommerce_loop_columns');
  108. add_filter( 'loop_shop_per_page', 'avia_woocommerce_product_count' );
  109.  
  110. //single page adds
  111. add_action( 'avia_add_to_cart', 'woocommerce_template_single_add_to_cart', 30, 2 );
  112.  
  113.  
  114.  
  115. /*update woocommerce v2*/
  116.  
  117. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); /*remove result count above products*/
  118. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); /*remove woocommerce ordering dropdown*/
  119. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); //remove rating
  120. remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 ); //remove woo pagination
  121.  
  122.  
  123. ######################################################################
  124. # FUNCTIONS
  125. ######################################################################
  126.  
  127. #
  128. # set the shop page id, otherwise avia_get_the_ID() can return a wrong id on the shop page
  129. #
  130. add_filter('avf_avia_get_the_ID','avia_set_shop_page_id', 10, 1);
  131. function avia_set_shop_page_id($id)
  132. {
  133. if(is_shop()) $id = woocommerce_get_page_id('shop');
  134. return $id;
  135. }
  136.  
  137. #
  138. # removes the default post image from shop overview pages and replaces it with this image
  139. #
  140. add_action( 'woocommerce_before_shop_loop_item_title', 'avia_woocommerce_thumbnail', 10);
  141. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
  142.  
  143. function avia_woocommerce_thumbnail($asdf)
  144. {
  145. global $product, $avia_config;
  146. $rating = $product->get_rating_html(); //get rating
  147.  
  148. $id = get_the_ID();
  149. $size = 'shop_catalog';
  150.  
  151. echo "<div class='thumbnail_container'>";
  152. echo avia_woocommerce_gallery_first_thumbnail( $id , $size);
  153. echo get_the_post_thumbnail( $id , $size );
  154. if(!empty($rating)) echo "<span class='rating_container'>".$rating."</span>";
  155. if($product->product_type == 'simple') echo "<span class='cart-loading'></span>";
  156. echo "</div>";
  157. }
  158.  
  159.  
  160. function avia_woocommerce_gallery_first_thumbnail($id, $size, $id_only = false)
  161. {
  162. $active_hover = get_post_meta( $id, '_product_hover', true );
  163.  
  164. if(!empty($active_hover))
  165. {
  166. $product_gallery = get_post_meta( $id, '_product_image_gallery', true );
  167.  
  168. if(!empty($product_gallery))
  169. {
  170. $gallery = explode(',',$product_gallery);
  171. $image_id = $gallery[0];
  172.  
  173. //return id only
  174. if(!empty($id_only)) return $image_id;
  175.  
  176. $image = wp_get_attachment_image( $image_id, $size, false, array( 'class' => "attachment-$size avia-product-hover" ));
  177.  
  178. //return image
  179. if(!empty($image)) return $image;
  180. }
  181. }
  182. }
  183.  
  184.  
  185.  
  186.  
  187. #
  188. # add ajax cart / options buttons to the product
  189. #
  190.  
  191. add_action( 'woocommerce_after_shop_loop_item', 'avia_add_cart_button', 16);
  192. function avia_add_cart_button()
  193. {
  194. global $product, $avia_config;
  195.  
  196. if ($product->product_type == 'bundle' ){
  197. $product = new WC_Product_Bundle($product->id);
  198. }
  199.  
  200. $extraClass = "";
  201.  
  202. ob_start();
  203. woocommerce_template_loop_add_to_cart();
  204. $output = ob_get_clean();
  205.  
  206. if(!empty($output))
  207. {
  208. $pos = strpos($output, ">");
  209.  
  210. if ($pos !== false) {
  211. $output = substr_replace($output,"><span ".av_icon_string('cart')."></span> ", $pos , strlen(1));
  212. }
  213. }
  214.  
  215.  
  216. if($product->product_type == 'variable' && empty($output))
  217. {
  218. $output = '<a class="add_to_cart_button button product_type_variable" href="'.get_permalink($product->id).'"><span '.av_icon_string("details").'></span> '.__("Select options","avia_framework").'</a>';
  219. }
  220.  
  221. if(in_array($product->product_type, array('subscription', 'simple', 'bundle')))
  222. {
  223. $output .= '<a class="button show_details_button" href="'.get_permalink($product->id).'"><span '.av_icon_string("details").'></span> '.__("Show Details","avia_framework").'</a>';
  224. }
  225. else
  226. {
  227. $extraClass = "single_button";
  228. }
  229.  
  230. if(empty($extraClass)) $output .= " <span class='button-mini-delimiter'></span>";
  231.  
  232.  
  233. if($output && !post_password_required()) echo "<div class='avia_cart_buttons $extraClass'>$output</div>";
  234. }
  235.  
  236.  
  237.  
  238.  
  239.  
  240. #
  241. # wrap products on overview pages into an extra div for improved styling options. adds "product_on_sale" class if prodct is on sale
  242. #
  243.  
  244. add_action( 'woocommerce_before_shop_loop_item', 'avia_shop_overview_extra_div', 5);
  245. function avia_shop_overview_extra_div()
  246. {
  247. global $product;
  248. $product_class = $product->is_on_sale() ? "product_on_sale" : "";
  249.  
  250. echo "<div class='inner_product main_color wrapped_style noLightbox $product_class'>";
  251. }
  252.  
  253. add_action( 'woocommerce_after_shop_loop_item', 'avia_close_div', 1000);
  254. function avia_close_div()
  255. {
  256. //echo "</div>";
  257. }
  258.  
  259.  
  260. #
  261. # wrap product titles and sale number on overview pages into an extra div for improved styling options
  262. #
  263.  
  264. add_action( 'woocommerce_before_shop_loop_item_title', 'avia_shop_overview_extra_header_div', 20);
  265. function avia_shop_overview_extra_header_div()
  266. {
  267. echo "<div class='inner_product_header'><div class='avia-arrow'></div>";
  268. }
  269.  
  270. add_action( 'woocommerce_after_shop_loop_item_title', 'avia_close_div', 1000);
  271.  
  272.  
  273. #
  274. # remove on sale badge from usual location and add it to the bottom of the product
  275. #
  276. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10);
  277. add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10);
  278.  
  279.  
  280. #
  281. # 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
  282. #
  283. function avia_shop_nav($args)
  284. {
  285. $output = "";
  286. $url = avia_collect_shop_urls();
  287.  
  288. $output .= "<ul>";
  289.  
  290. if( is_user_logged_in() )
  291. {
  292. $current = $sub1 = $sub2 = $sub3 = "";
  293. if(is_account_page()) $current = "current-menu-item";
  294. if(is_page(get_option('woocommerce_change_password_page_id'))) $sub1 = "current-menu-item";
  295. if(is_page(get_option('woocommerce_edit_address_page_id'))) $sub2 = "current-menu-item";
  296. if(is_page(get_option('woocommerce_view_order_page_id'))) $sub3 = "current-menu-item";
  297.  
  298.  
  299. $output .= "<li class='$current account_overview_link'><a href='".$url['account_overview']."'>".__('My Account', 'avia_framework')."</a>";
  300. $output .= "<ul>";
  301. $output .= "<li class='$sub1 account_change_pw_link'><a href='".$url['account_change_pw']."'>".__('Change Password', 'avia_framework')."</a></li>";
  302. $output .= "<li class='$sub2 account_edit_adress_link'><a href='".$url['account_edit_adress']."'>".__('Edit Address', 'avia_framework')."</a></li>";
  303. $output .= "<li class='$sub3 account_view_order_link'><a href='".$url['account_view_order']."'>".__('View Order', 'avia_framework')."</a></li>";
  304. $output .= "</ul>";
  305. $output .= "</li>";
  306. $output .= "<li class='account_logout_link'><a href='".$url['logout']."'>".__('Log Out', 'avia_framework')."</a></li>";
  307. }
  308. else
  309. {
  310. $sub1 = $sub2 = "";
  311. if(is_page(get_option('woocommerce_myaccount_page_id')))
  312. {
  313. if(isset($_GET['account_visible']) && $_GET['account_visible'] == 'register') $sub1 = "current-menu-item";
  314. if(isset($_GET['account_visible']) && $_GET['account_visible'] == 'login') $sub2 = "current-menu-item";
  315. }
  316.  
  317. $url_param = strpos($url['account_overview'], '?') === false ? "?" : "&";
  318.  
  319. if (get_option('woocommerce_enable_myaccount_registration') =='yes')
  320. {
  321. $output .= "<li class='register_link $sub1'><a href='".$url['account_overview'].$url_param."account_visible=register'>".__('Register', 'avia_framework')."</a></li>";
  322. }
  323.  
  324. $output .= "<li class='login_link $sub2'><a href='".$url['account_overview'].$url_param."account_visible=login'>".__('Log In', 'avia_framework')."</a></li>";
  325. }
  326.  
  327. $output .= "</ul>";
  328.  
  329. if($args['echo'] == true)
  330. {
  331. echo $output;
  332. }
  333. else
  334. {
  335. return $output;
  336. }
  337. }
  338.  
  339.  
  340. #
  341. # helper function that collects all the necessary urls for the shop navigation
  342. #
  343.  
  344. function avia_collect_shop_urls()
  345. {
  346. global $woocommerce;
  347.  
  348. $url['cart'] = $woocommerce->cart->get_cart_url();
  349. $url['checkout'] = $woocommerce->cart->get_checkout_url();
  350. $url['account_overview'] = get_permalink(get_option('woocommerce_myaccount_page_id'));
  351. $url['account_edit_adress'] = get_permalink(get_option('woocommerce_edit_address_page_id'));
  352. $url['account_view_order'] = get_permalink(get_option('woocommerce_view_order_page_id'));
  353. $url['account_change_pw'] = get_permalink(get_option('woocommerce_change_password_page_id'));
  354. $url['logout'] = wp_logout_url(home_url('/'));
  355.  
  356. return $url;
  357. }
  358.  
  359.  
  360.  
  361.  
  362. #
  363. # check which page is displayed and if the automatic sidebar menu for subpages should be prevented
  364. #
  365. add_filter( 'avf_sidebar_menu_filter', 'avia_woocommerce_sidebar_filter');
  366.  
  367. function avia_woocommerce_sidebar_filter($menu)
  368. {
  369. $id = avia_get_the_ID();
  370. if(is_cart() || is_checkout() || get_option('woocommerce_thanks_page_id') == $id){$menu = "";}
  371. return $menu;
  372. }
  373.  
  374.  
  375. #
  376. # check if a single product is displayed and always set the sidebar styling to that of a right sidebar
  377. #
  378. add_filter( 'avf_sidebar_position', 'avia_woocommerce_sidebar_pos');
  379.  
  380. function avia_woocommerce_sidebar_pos($sidebar)
  381. {
  382. if(is_product())
  383. {
  384. $sidebar = "sidebar_right";
  385. }
  386.  
  387. return $sidebar;
  388. }
  389.  
  390.  
  391.  
  392. function avia_add_to_cart($post, $product )
  393. {
  394. echo "<div class='avia_cart avia_cart_".$product->product_type."'>";
  395. do_action( 'avia_add_to_cart', $post, $product );
  396. echo "</div>";
  397. }
  398.  
  399.  
  400.  
  401. #
  402. # replace thumbnail image size with full size image on single pages
  403. #
  404. /*
  405.  
  406. add_filter( 'single_product_small_thumbnail_size', 'avia_woocommerce_thumb_size');
  407.  
  408. function avia_woocommerce_thumb_size()
  409. {
  410. return 'shop_single';
  411. }
  412. */
  413.  
  414.  
  415.  
  416.  
  417. #
  418. # if we are viewing a woocommerce page modify the breadcrumb nav
  419. #
  420.  
  421. if(!function_exists('avia_woocommerce_breadcrumb'))
  422. {
  423. add_filter('avia_breadcrumbs_trail','avia_woocommerce_breadcrumb');
  424.  
  425. function avia_woocommerce_breadcrumb($trail)
  426. {
  427. global $avia_config;
  428.  
  429. if(is_woocommerce())
  430. {
  431.  
  432. $home = $trail[0];
  433. $last = array_pop($trail);
  434. $shop_id = woocommerce_get_page_id('shop');
  435. $taxonomy = "product_cat";
  436.  
  437. // on the shop frontpage simply display the shop name, rather than shop name + "All Products"
  438. if(is_shop())
  439. {
  440. if(!empty($shop_id) && $shop_id != -1) $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
  441. $last = "";
  442.  
  443. if(is_search())
  444. {
  445. $last = __('Search results for:','avia_framework').' '.esc_attr($_GET['s']);
  446. }
  447. }
  448.  
  449. // on the product page single page modify the breadcrumb to read [home] [if available:parent shop pages] [shop] [if available:parent categories] [category] [title]
  450. if(is_product())
  451. {
  452. //fetch all product categories and search for the ones with parents. if none are avalaible use the first category found
  453. $product_category = $parent_cat = array();
  454. $temp_cats = get_the_terms(get_the_ID(), $taxonomy);
  455.  
  456. if(!empty($temp_cats))
  457. {
  458. foreach($temp_cats as $key => $cat)
  459. {
  460. if($cat->parent != 0 && !in_array($cat->term_taxonomy_id, $parent_cat))
  461. {
  462. $product_category[] = $cat;
  463. $parent_cat[] = $cat->parent;
  464. }
  465. }
  466.  
  467. //if no categories with parents use the first one
  468. if(empty($product_category)) $product_category[] = reset($temp_cats);
  469.  
  470. }
  471. //unset the trail and build our own
  472. unset($trail);
  473.  
  474. $trail[0] = $home;
  475. if(!empty($shop_id) && $shop_id != -1) $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
  476. if(!empty($parent_cat)) $trail = array_merge( $trail, avia_breadcrumbs_get_term_parents( $parent_cat[0] , $taxonomy ) );
  477. 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>';
  478.  
  479. }
  480.  
  481.  
  482. // add the [shop] trail to category/tag pages: [home] [if available:parent shop pages] [shop] [if available:parent categories] [category/tag]
  483. if(is_product_category() || is_product_tag())
  484. {
  485. if(!empty($shop_id) && $shop_id != -1)
  486. {
  487. $shop_trail = avia_breadcrumbs_get_parents( $shop_id ) ;
  488. array_splice($trail, 1, 0, $shop_trail);
  489. }
  490. }
  491.  
  492. if(is_product_tag())
  493. {
  494. $last = __("Tag",'avia_framework').": ".$last;
  495. }
  496.  
  497.  
  498. if(!empty($last)) $trail[] = $last;
  499. }
  500.  
  501. return $trail;
  502. }
  503.  
  504. }
  505.  
  506.  
  507.  
  508. #
  509. # creates the avia framework container arround the shop pages
  510. #
  511. add_action( 'woocommerce_before_main_content', 'avia_woocommerce_before_main_content', 10);
  512.  
  513.  
  514. function avia_woocommerce_before_main_content()
  515. {
  516. global $avia_config;
  517.  
  518. if(!isset($avia_config['shop_overview_column'])) $avia_config['shop_overview_column'] = "auto";
  519.  
  520. $id = get_option('woocommerce_shop_page_id');
  521. $layout = get_post_meta($id, 'layout', true);
  522.  
  523. if(!empty($layout))
  524. {
  525. $avia_config['layout']['current'] = $avia_config['layout'][$layout];
  526. $avia_config['layout']['current']['main'] = $layout;
  527. }
  528.  
  529. $avia_config['layout'] = apply_filters('avia_layout_filter', $avia_config['layout'], $id);
  530.  
  531. $title_args = array();
  532.  
  533. if(is_woocommerce())
  534. {
  535. $t_link = "";
  536.  
  537. if(is_shop()) $title = get_option('woocommerce_shop_page_title');
  538.  
  539. $shop_id = woocommerce_get_page_id('shop');
  540. if($shop_id && $shop_id != -1)
  541. {
  542. if(empty($title)) $title = get_the_title($shop_id);
  543. $t_link = get_permalink($shop_id);
  544. }
  545.  
  546. if(empty($title)) $title = __("Shop",'avia_framework');
  547.  
  548. if(is_product_category() || is_product_tag())
  549. {
  550. global $wp_query;
  551. $tax = $wp_query->get_queried_object();
  552. $title = $tax->name;
  553. $t_link = '';
  554. }
  555.  
  556. $title_args = array('title' => $title, 'link' => $t_link);
  557. }
  558.  
  559. if( get_post_meta(get_the_ID(), 'header', true) != 'no') echo avia_title($title_args);
  560.  
  561. echo "<div class='container_wrap container_wrap_first main_color ".avia_layout_class( 'main' , false )." template-shop shop_columns_".$avia_config['shop_overview_column']."'>";
  562.  
  563. echo "<div class='container'>";
  564.  
  565. if(!is_singular()) { $avia_config['overview'] = true; }
  566. }
  567.  
  568. #
  569. # closes the avia framework container arround the shop pages
  570. #
  571.  
  572. add_action( 'woocommerce_after_main_content', 'avia_woocommerce_after_main_content', 10);
  573. function avia_woocommerce_after_main_content()
  574. {
  575.  
  576. global $avia_config;
  577. $avia_config['currently_viewing'] = "shop";
  578.  
  579. //reset all previous queries
  580. wp_reset_query();
  581.  
  582. //get the sidebar
  583. if(!is_singular())
  584. get_sidebar();
  585.  
  586. // echo "</div>"; // end container - gets already closed at the top of footer.php
  587.  
  588. echo "</div>"; // end tempate-shop content
  589. echo "</div>"; // close default .container_wrap element
  590. }
  591.  
  592.  
  593.  
  594.  
  595. #
  596. # wrap an empty product search into extra div
  597. #
  598. add_action( 'woocommerce_before_main_content', 'avia_woocommerce_404_search', 9111);
  599. function avia_woocommerce_404_search()
  600. {
  601. global $wp_query;
  602.  
  603. if( (is_search() || is_archive()) && empty($wp_query->found_posts) )
  604. {
  605. echo "<div class='template-page template-search template-search-none content ".avia_layout_class( 'content', false )." units'>";
  606. echo "<div class='entry entry-content-wrapper' id='search-fail'>";
  607. }
  608. }
  609.  
  610. add_action( 'woocommerce_after_main_content', 'avia_woocommerce_404_search_close', 1);
  611. function avia_woocommerce_404_search_close()
  612. {
  613. global $wp_query;
  614.  
  615. if( (is_search() || is_shop() || is_archive()) && empty($wp_query->found_posts) )
  616. {
  617. get_template_part('includes/error404');
  618. echo "</div>";
  619. echo "</div>"; // close default .container_wrap element
  620. }
  621. }
  622.  
  623.  
  624.  
  625.  
  626. #
  627. # modifies the class of a page so we can display single login and single register
  628. #
  629. add_filter( 'avia_layout_class_filter_main', 'avia_register_login_class');
  630.  
  631. function avia_register_login_class($layout)
  632. {
  633. if(isset($_GET['account_visible']))
  634. {
  635. if($_GET['account_visible'] == 'register') $layout .= " template-register";
  636. if($_GET['account_visible'] == 'login') $layout .= " template-login";
  637. }
  638.  
  639. return $layout;
  640. }
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648. #
  649. # creates the avia framework content container arround the shop loop
  650. #
  651. add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_before_shop_loop', 1);
  652.  
  653. function avia_woocommerce_before_shop_loop()
  654. {
  655.  
  656. global $avia_config;
  657. if(isset($avia_config['dynamic_template'])) return;
  658. $markup = avia_markup_helper(array('context' => 'content','echo'=>false,'post_type'=>'products'));
  659. echo "<main class='template-shop content ".avia_layout_class( 'content' , false)." units' $markup><div class='entry-content-wrapper'>";
  660. }
  661.  
  662. #
  663. # closes the avia framework content container arround the shop loop
  664. #
  665. add_action( 'woocommerce_after_shop_loop', 'avia_woocommerce_after_shop_loop', 10);
  666.  
  667. function avia_woocommerce_after_shop_loop()
  668. {
  669. global $avia_config;
  670. if(isset($avia_config['dynamic_template'])) return;
  671. if(isset($avia_config['overview'] )) echo avia_pagination('', 'nav');
  672. echo "</div></main>"; //end content
  673. }
  674.  
  675.  
  676.  
  677. #
  678. # echo the excerpt
  679. #
  680. function avia_woocommerce_overview_excerpt()
  681. {
  682. global $avia_config;
  683.  
  684. if(!empty($avia_config['shop_overview_excerpt']))
  685. {
  686. echo "<div class='product_excerpt'>";
  687. the_excerpt();
  688. echo "</div>";
  689. }
  690. }
  691.  
  692.  
  693.  
  694. #
  695. # creates the preview images based on page/category image
  696. #
  697. remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
  698. remove_action( 'woocommerce_product_archive_description', 'woocommerce_product_archive_description', 10 );
  699.  
  700. add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_overview_banner_image', 10);
  701. add_action( 'woocommerce_before_shop_loop', 'woocommerce_taxonomy_archive_description', 11 );
  702. //add_action( 'woocommerce_before_shop_loop', 'woocommerce_product_archive_description', 12 ); //causes warning
  703.  
  704.  
  705. function avia_woocommerce_overview_banner_image()
  706. {
  707. global $avia_config;
  708. if(avia_is_dynamic_template() || is_paged() || is_search() ) return false;
  709.  
  710. $image_size = "entry_with_sidebar";
  711. $layout = avia_layout_class( 'main' , false );
  712. if($layout == 'fullsize') $image_size = 'entry_without_sidebar';
  713.  
  714. if(is_shop())
  715. {
  716. $shop_id = woocommerce_get_page_id('shop');
  717. if($shop_id != -1)
  718. {
  719. $image = get_the_post_thumbnail($shop_id, $image_size);
  720. if($image) echo "<div class='page-thumb'>{$image}</div>";
  721. }
  722. }
  723.  
  724. if(is_product_category())
  725. {
  726. global $wp_query;
  727. $image = "";
  728. if(isset($wp_query->query_vars['taxonomy']))
  729. {
  730. $term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']);
  731.  
  732. if(!empty($term->term_id))
  733. {
  734. $attachment_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id');
  735.  
  736. if(!empty($attachment_id))
  737. {
  738. $image = wp_get_attachment_image( $attachment_id, $image_size, false, array('class'=>'category_thumb'));
  739. if($image) echo "<div class='page-thumb'>{$image}</div>";
  740. }
  741. }
  742. }
  743. }
  744.  
  745. }
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753. #
  754. # creates the title + description for overview pages
  755. #
  756. function avia_woocommerce_advanced_title()
  757. {
  758.  
  759. global $wp_query;
  760. $titleClass = "";
  761. $image = "";
  762.  
  763.  
  764. if(!empty($attachment_id))
  765. {
  766. $titleClass .= "title_container_image ";
  767. $image = wp_get_attachment_image( $attachment_id, 'thumbnail', false, array('class'=>'category_thumb'));
  768. }
  769.  
  770. echo "<div class='extralight-border title_container shop_title_container $titleClass'>";
  771. //echo avia_breadcrumbs();
  772. woocommerce_catalog_ordering();
  773. echo $image;
  774. }
  775.  
  776.  
  777.  
  778.  
  779.  
  780. #
  781. # place the cart button according to the header layout (top/sidebar)
  782. #
  783. add_action( 'init', 'avia_woocommerce_cart_placement', 10);
  784.  
  785. function avia_woocommerce_cart_placement()
  786. {
  787. $position = avia_get_option('header_position', 'header_top') == "header_top" ? "ava_main_header" : "ava_inside_main_menu";
  788. add_action( $position, 'avia_woocommerce_cart_dropdown', 10);
  789. }
  790.  
  791.  
  792.  
  793. function avia_woocommerce_cart_dropdown()
  794. {
  795. global $woocommerce, $avia_config;
  796. $cart_subtotal = $woocommerce->cart->get_cart_subtotal();
  797. $link = $woocommerce->cart->get_cart_url();
  798.  
  799.  
  800. $output = "";
  801. $output .= "<ul class = 'cart_dropdown' data-success='".__('was added to the cart', 'avia_framework')."'><li class='cart_dropdown_first'>";
  802. $output .= "<a class='cart_dropdown_link' href='".$link."'><span class='avia_hidden_link_text'>".__('Cart','avia_framework')."</span><span ".av_icon_string('cart')."></span></a><!--<span class='cart_subtotal'>".$cart_subtotal."</span>-->";
  803. $output .= "<div class='dropdown_widget dropdown_widget_cart'><div class='avia-arrow'></div>";
  804. $output .= '<div class="widget_shopping_cart_content"></div>';
  805. $output .= "</div>";
  806. $output .= "</li></ul>";
  807.  
  808. echo $output;
  809. }
  810.  
  811.  
  812.  
  813. #
  814. # modify shop overview column count
  815. #
  816. function avia_woocommerce_loop_columns()
  817. {
  818. global $avia_config;
  819. return $avia_config['shop_overview_column'];
  820. }
  821.  
  822.  
  823. #
  824. # modify shop overview product count
  825. #
  826.  
  827. function avia_woocommerce_product_count()
  828. {
  829. global $avia_config;
  830. return $avia_config['shop_overview_products'];
  831. }
  832.  
  833.  
  834. #
  835. # filter cross sells on the cart page. display 4 on fullwidth pages and 3 on carts with sidebar
  836. #
  837.  
  838. add_filter('woocommerce_cross_sells_total', 'avia_woocommerce_cross_sale_count');
  839. add_filter('woocommerce_cross_sells_columns', 'avia_woocommerce_cross_sale_count');
  840.  
  841. function avia_woocommerce_cross_sale_count($count)
  842. {
  843. return 4;
  844. }
  845.  
  846. #
  847. # move cross sells below the shipping
  848. #
  849.  
  850. remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
  851. add_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display' , 10);
  852.  
  853.  
  854.  
  855.  
  856. #
  857. # display tabs and related items within the summary wrapper
  858. #
  859. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
  860. add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 1 );
  861.  
  862.  
  863.  
  864. #
  865. # display upsells and related products within dedicated div with different column and number of products
  866. #
  867. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products',20);
  868. remove_action( 'woocommerce_after_single_product', 'woocommerce_output_related_products',10);
  869. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_output_related_products', 20);
  870.  
  871. function avia_woocommerce_output_related_products()
  872. {
  873. global $avia_config;
  874. $output = "";
  875.  
  876. ob_start();
  877. woocommerce_related_products(array('posts_per_page'=>$avia_config['shop_single_column_items'], 'columns'=>$avia_config['shop_single_column'])); // X products, X columns
  878. $content = ob_get_clean();
  879. if($content)
  880. {
  881. $output .= "<div class='product_column product_column_".$avia_config['shop_single_column']."'>";
  882. //$output .= "<h3>".(__('Related Products', 'avia_framework'))."</h3>";
  883. $output .= $content;
  884. $output .= "</div>";
  885. }
  886.  
  887. $avia_config['woo_related'] = $output;
  888.  
  889. }
  890.  
  891. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
  892. remove_action( 'woocommerce_after_single_product', 'woocommerce_upsell_display',10);
  893. 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
  894.  
  895. function avia_woocommerce_output_upsells()
  896. {
  897. global $avia_config;
  898.  
  899. $output = "";
  900.  
  901. ob_start();
  902. woocommerce_upsell_display($avia_config['shop_single_column_items'],$avia_config['shop_single_column']); // 4 products, 4 columns
  903. $content = ob_get_clean();
  904. if($content)
  905. {
  906. $output .= "<div class='product_column product_column_".$avia_config['shop_single_column']."'>";
  907. //$output .= "<h3>".(__('You may also like', 'avia_framework'))."</h3>";
  908. $output .= $content;
  909. $output .= "</div>";
  910. }
  911.  
  912. $avia_config['woo_upsells'] = $output;
  913.  
  914. }
  915.  
  916. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_display_output_upsells', 30); //display the related products and upsells
  917.  
  918. function avia_woocommerce_display_output_upsells()
  919. {
  920. global $avia_config;
  921.  
  922. $products = $avia_config['woo_upsells'].$avia_config['woo_related'];
  923.  
  924. if(!empty($products))
  925. {
  926. $output .= $products;
  927. $output .= "</div>";
  928.  
  929. echo $output;
  930. }
  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. if(!function_exists('avia_add_image_div'))
  941. {
  942. function avia_add_image_div()
  943. {
  944. echo "<div class='single-product-main-image alpha'>";
  945. }
  946. }
  947.  
  948.  
  949.  
  950. if(!function_exists('avia_close_image_div'))
  951. {
  952. function avia_close_image_div()
  953. {
  954. global $avia_config;
  955. if(is_product()) {
  956. $avia_config['currently_viewing'] = "shop_single";
  957. get_sidebar();
  958. }
  959. echo "</div>";
  960. }
  961. }
  962.  
  963.  
  964.  
  965. #
  966. # wrap single product summary in an extra div
  967. #
  968. add_action( 'woocommerce_before_single_product_summary', 'avia_add_summary_div', 25);
  969. add_action( 'woocommerce_after_single_product_summary', 'avia_close_div', 3);
  970.  
  971. if(!function_exists('avia_add_summary_div'))
  972. {
  973. function avia_add_summary_div()
  974. {
  975. echo "<div class='single-product-summary'>";
  976. }
  977. }
  978.  
  979. //remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
  980.  
  981.  
  982.  
  983.  
  984. #
  985. # displays a front end interface for modifying the shoplist query parameters like sorting order, product count etc
  986. #
  987. if(!function_exists('avia_woocommerce_frontend_search_params'))
  988. {
  989. add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_frontend_search_params', 20);
  990.  
  991. function avia_woocommerce_frontend_search_params()
  992. {
  993. global $avia_config;
  994.  
  995. if(!empty($avia_config['woocommerce']['disable_sorting_options'])) return false;
  996.  
  997. $product_order['default'] = __("Default Order",'avia_framework');
  998. $product_order['title'] = __("Name",'avia_framework');
  999. $product_order['price'] = __("Price",'avia_framework');
  1000. $product_order['date'] = __("Date",'avia_framework');
  1001. $product_order['popularity'] = __("Popularity",'avia_framework');
  1002.  
  1003. $product_sort['asc'] = __("Click to order products ascending", 'avia_framework');
  1004. $product_sort['desc'] = __("Click to order products descending", 'avia_framework');
  1005.  
  1006. $per_page_string = __("Products per page",'avia_framework');
  1007.  
  1008.  
  1009. $per_page = get_option('avia_woocommerce_product_count');
  1010. if(!$per_page) $per_page = get_option('posts_per_page');
  1011. if(!empty($avia_config['woocommerce']['default_posts_per_page'])) $per_page = $avia_config['woocommerce']['default_posts_per_page'];
  1012.  
  1013.  
  1014. parse_str($_SERVER['QUERY_STRING'], $params);
  1015.  
  1016. $po_key = !empty($avia_config['woocommerce']['product_order']) ? $avia_config['woocommerce']['product_order'] : 'default';
  1017. $ps_key = !empty($avia_config['woocommerce']['product_sort']) ? $avia_config['woocommerce']['product_sort'] : 'asc';
  1018. $pc_key = !empty($avia_config['woocommerce']['product_count']) ? $avia_config['woocommerce']['product_count'] : $per_page;
  1019.  
  1020. $ps_key = strtolower($ps_key);
  1021.  
  1022. $nofollow = 'rel="nofollow"';
  1023.  
  1024. //generate markup
  1025. $output = "";
  1026. $output .= "<div class='product-sorting'>";
  1027. $output .= " <ul class='sort-param sort-param-order'>";
  1028. $output .= " <li><span class='currently-selected'>".__("Sort by",'avia_framework')." <strong>".$product_order[$po_key]."</strong></span>";
  1029. $output .= " <ul>";
  1030. $output .= " <li".avia_woo_active_class($po_key, 'default')."><a href='".avia_woo_build_query_string($params, 'product_order', 'default')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['default']."</a></li>";
  1031. $output .= " <li".avia_woo_active_class($po_key, 'title')."><a href='".avia_woo_build_query_string($params, 'product_order', 'title')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['title']."</a></li>";
  1032. $output .= " <li".avia_woo_active_class($po_key, 'price')."><a href='".avia_woo_build_query_string($params, 'product_order', 'price')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['price']."</a></li>";
  1033. $output .= " <li".avia_woo_active_class($po_key, 'date')."><a href='".avia_woo_build_query_string($params, 'product_order', 'date')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['date']."</a></li>";
  1034. $output .= " <li".avia_woo_active_class($po_key, 'popularity')."><a href='".avia_woo_build_query_string($params, 'product_order', 'popularity')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['popularity']."</a></li>";
  1035. $output .= " </ul>";
  1036. $output .= " </li>";
  1037. $output .= " </ul>";
  1038.  
  1039. $output .= " <ul class='sort-param sort-param-sort'>";
  1040. $output .= " <li>";
  1041. if($ps_key == 'desc') $output .= " <a title='".$product_sort['asc']."' class='sort-param-asc' href='".avia_woo_build_query_string($params, 'product_sort', 'asc')."' {$nofollow}>".$product_sort['desc']."</a>";
  1042. if($ps_key == 'asc') $output .= " <a title='".$product_sort['desc']."' class='sort-param-desc' href='".avia_woo_build_query_string($params, 'product_sort', 'desc')."' {$nofollow}>".$product_sort['asc']."</a>";
  1043. $output .= " </li>";
  1044. $output .= " </ul>";
  1045.  
  1046. $output .= " <ul class='sort-param sort-param-count'>";
  1047. $output .= " <li><span class='currently-selected'>".__("Display",'avia_framework')." <strong>".$pc_key." ".$per_page_string."</strong></span>";
  1048. $output .= " <ul>";
  1049. $output .= " <li".avia_woo_active_class($pc_key, $per_page)."> <a href='".avia_woo_build_query_string($params, 'product_count', $per_page)."' {$nofollow}> <span class='avia-bullet'></span>".$per_page." ".$per_page_string."</a></li>";
  1050. $output .= " <li".avia_woo_active_class($pc_key, $per_page*2)."><a href='".avia_woo_build_query_string($params, 'product_count', $per_page * 2)."' {$nofollow}> <span class='avia-bullet'></span>".($per_page * 2)." ".$per_page_string."</a></li>";
  1051. $output .= " <li".avia_woo_active_class($pc_key, $per_page*3)."><a href='".avia_woo_build_query_string($params, 'product_count', $per_page * 3)."' {$nofollow}> <span class='avia-bullet'></span>".($per_page * 3)." ".$per_page_string."</a></li>";
  1052. $output .= " </ul>";
  1053. $output .= " </li>";
  1054. $output .= " </ul>";
  1055.  
  1056.  
  1057.  
  1058. $output .= "</div>";
  1059. echo $output;
  1060. }
  1061. }
  1062.  
  1063. //helper function to create the active list class
  1064. if(!function_exists('avia_woo_active_class'))
  1065. {
  1066. function avia_woo_active_class($key1, $key2)
  1067. {
  1068. if($key1 == $key2) return " class='current-param'";
  1069. }
  1070. }
  1071.  
  1072.  
  1073. //helper function to build the query strings for the catalog ordering menu
  1074. if(!function_exists('avia_woo_build_query_string'))
  1075. {
  1076. function avia_woo_build_query_string($params = array(), $overwrite_key, $overwrite_value)
  1077. {
  1078. $params[$overwrite_key] = $overwrite_value;
  1079. $paged = (array_key_exists('product_count', $params)) ? 'paged=1&' : '';
  1080. return "?" . $paged . http_build_query($params);
  1081. }
  1082. }
  1083.  
  1084. //function that actually overwrites the query parameters
  1085. if(!function_exists('avia_woocommerce_overwrite_catalog_ordering'))
  1086. {
  1087. add_action( 'woocommerce_get_catalog_ordering_args', 'avia_woocommerce_overwrite_catalog_ordering', 20);
  1088.  
  1089. function avia_woocommerce_overwrite_catalog_ordering($args)
  1090. {
  1091. global $avia_config;
  1092.  
  1093. if(!empty($avia_config['woocommerce']['disable_sorting_options'])) return $args;
  1094.  
  1095. //check the folllowing get parameters and session vars. if they are set overwrite the defaults
  1096. $check = array('product_order', 'product_count', 'product_sort');
  1097. if(empty($avia_config['woocommerce'])) $avia_config['woocommerce'] = array();
  1098.  
  1099. foreach($check as $key)
  1100. {
  1101. if(isset($_GET[$key]) ) $_SESSION['avia_woocommerce'][$key] = esc_attr($_GET[$key]);
  1102. if(isset($_SESSION['avia_woocommerce'][$key]) ) $avia_config['woocommerce'][$key] = $_SESSION['avia_woocommerce'][$key];
  1103. }
  1104.  
  1105.  
  1106. // is user wants to use new product order remove the old sorting parameter
  1107. if(isset($_GET['product_order']) && !isset($_GET['product_sort']) && isset($_SESSION['avia_woocommerce']['product_sort']))
  1108. {
  1109. unset($_SESSION['avia_woocommerce']['product_sort'], $avia_config['woocommerce']['product_sort']);
  1110. }
  1111.  
  1112. extract($avia_config['woocommerce']);
  1113.  
  1114. // set the product order
  1115. if(!empty($product_order))
  1116. {
  1117. switch ( $product_order ) {
  1118. case 'date' : $orderby = 'date'; $order = 'desc'; $meta_key = ''; break;
  1119. case 'price' : $orderby = 'meta_value_num'; $order = 'asc'; $meta_key = '_price'; break;
  1120. case 'popularity' : $orderby = 'meta_value_num'; $order = 'desc'; $meta_key = 'total_sales'; break;
  1121. case 'title' : $orderby = 'title'; $order = 'asc'; $meta_key = ''; break;
  1122. case 'default':
  1123. default : $orderby = 'menu_order title'; $order = 'asc'; $meta_key = ''; break;
  1124. }
  1125. }
  1126.  
  1127.  
  1128.  
  1129. // set the product count
  1130. if(!empty($product_count) && is_numeric($product_count))
  1131. {
  1132. $avia_config['shop_overview_products_overwritten'] = true;
  1133. $avia_config['shop_overview_products'] = (int) $product_count;
  1134. }
  1135.  
  1136. //set the product sorting
  1137. if(!empty($product_sort))
  1138. {
  1139. switch ( $product_sort ) {
  1140. case 'desc' : $order = 'desc'; break;
  1141. case 'asc' : $order = 'asc'; break;
  1142. default : $order = 'asc'; break;
  1143. }
  1144. }
  1145.  
  1146.  
  1147. if(isset($orderby)) $args['orderby'] = $orderby;
  1148. if(isset($order)) $args['order'] = $order;
  1149. if (!empty($meta_key))
  1150. {
  1151. $args['meta_key'] = $meta_key;
  1152. }
  1153.  
  1154.  
  1155. $avia_config['woocommerce']['product_sort'] = $args['order'];
  1156.  
  1157. return $args;
  1158. }
  1159.  
  1160.  
  1161. }
  1162.  
  1163. //remove produt information on password protected products
  1164. if(!function_exists('avia_woocommerce_remove_hooks'))
  1165. {
  1166. add_action('woocommerce_before_single_product', 'avia_woocommerce_remove_hooks');
  1167.  
  1168. function avia_woocommerce_remove_hooks()
  1169. {
  1170. /*remove content from password protected products*/
  1171. if(post_password_required())
  1172. {
  1173. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_echo_password', 1 );
  1174. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 1 );
  1175. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
  1176. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
  1177. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
  1178. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
  1179. remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
  1180. remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
  1181. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
  1182. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
  1183. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  1184. remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
  1185. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
  1186. remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
  1187. remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
  1188. remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
  1189. remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
  1190.  
  1191. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
  1192. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
  1193. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
  1194. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
  1195. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
  1196. }
  1197. }
  1198. }
  1199.  
  1200. if(!function_exists('avia_woocommerce_echo_password'))
  1201. {
  1202. add_action('ava_woocomemrce_password_protection_remove_hooks', 'avia_woocommerce_remove_hooks');
  1203.  
  1204. function avia_woocommerce_echo_password()
  1205. {
  1206. /*remove content from password protected products*/
  1207. if(post_password_required())
  1208. {
  1209. echo get_the_password_form();
  1210. }
  1211. }
  1212. }
  1213.  
  1214.  
  1215.  
  1216.  
  1217. if(!function_exists('avia_woocommerce_post_thumbnail_description'))
  1218. {
  1219. add_filter('woocommerce_single_product_image_html','avia_woocommerce_post_thumbnail_description', 10, 2);
  1220. function avia_woocommerce_post_thumbnail_description($img, $post_id)
  1221. {
  1222. global $post, $woocommerce, $product;
  1223.  
  1224. if(has_post_thumbnail())
  1225. {
  1226. $image_title = esc_attr(get_post_field('post_content', get_post_thumbnail_id()));
  1227. $image_link = wp_get_attachment_url( get_post_thumbnail_id() );
  1228. $image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
  1229. 'title' => $image_title
  1230. ) );
  1231. $attachment_count = count( $product->get_gallery_attachment_ids() );
  1232.  
  1233. if ( $attachment_count > 0 ) {
  1234. $gallery = '[product-gallery]';
  1235. } else {
  1236. $gallery = '';
  1237. }
  1238.  
  1239. return sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image);
  1240. }
  1241.  
  1242. return $img;
  1243. }
  1244. }
  1245.  
  1246. if(!function_exists('avia_woocommerce_gallery_thumbnail_description'))
  1247. {
  1248. add_filter('woocommerce_single_product_image_thumbnail_html','avia_woocommerce_gallery_thumbnail_description', 10, 4);
  1249. function avia_woocommerce_gallery_thumbnail_description($img, $attachment_id, $post_id, $image_class )
  1250. {
  1251. $image_link = wp_get_attachment_url( $attachment_id );
  1252.  
  1253. if(!$image_link) return $img;
  1254.  
  1255. $image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) );
  1256. $image_title = esc_attr(get_post_field('post_content', $attachment_id));
  1257.  
  1258. $img = sprintf( '<a href="%s" class="%s" title="%s" rel="prettyPhoto[product-gallery]">%s</a>', $image_link, $image_class, $image_title, $image );
  1259.  
  1260. return $img;
  1261. }
  1262. }
  1263.  
  1264.  
  1265. if(!function_exists('avia_title_args_woopage'))
  1266. {
  1267. add_filter('avf_title_args','avia_title_args_woopage', 10, 4);
  1268. function avia_title_args_woopage($args)
  1269. {
  1270. if(is_single() && is_product())
  1271. {
  1272. $args['heading'] = "strong";
  1273. }
  1274.  
  1275. return $args;
  1276. }
  1277. }
  1278.  
  1279.  
  1280. /*
  1281. Function that is able to overwrite the default "shop" page used by woocommerce so the template builder can be used
  1282. Will only be executed if the user has switched the "shop" page to advanced layout builder. Default products are no longer displayed
  1283. and the user needs to add a product grid element
  1284.  
  1285. Can be activated by adding
  1286.  
  1287. add_theme_support( 'avia_custom_shop_page' );
  1288.  
  1289. to your functions.php file
  1290. */
  1291. if(!function_exists('avia_woocommerce_default_page'))
  1292. {
  1293. add_filter( 'pre_get_posts', 'avia_woocommerce_default_page' );
  1294.  
  1295. function avia_woocommerce_default_page($query)
  1296. {
  1297. if(current_theme_supports('avia_custom_shop_page'))
  1298. {
  1299. if(!$query->is_admin && $query->is_main_query() && !$query->is_tax && $query->is_archive && $query->is_post_type_archive)
  1300. {
  1301. $vars = $query->query_vars;
  1302.  
  1303. if(isset($vars['post_type']) && 'product' == $vars['post_type'] )
  1304. {
  1305. $shop_page_id = wc_get_page_id( 'shop' );
  1306. $builder_active = AviaHelper::builder_status($shop_page_id);
  1307.  
  1308. if($builder_active == "active")
  1309. {
  1310. $query->set( 'post_type', 'page' );
  1311. $query->set( 'p', $shop_page_id );
  1312. $query->set( 'meta_query', array() );
  1313.  
  1314. $query->is_singular = true;
  1315. $query->is_page = true;
  1316. $query->is_archive = false;
  1317. $query->is_post_type_archive = false;
  1318. $query->query = array('p'=>$shop_page_id, 'post_type' => 'page');
  1319. }
  1320. }
  1321. }
  1322. }
  1323.  
  1324. return $query;
  1325.  
  1326. }
  1327. }
  1328.  
  1329.  
  1330.  
  1331. if(!function_exists('avia_woocommerce_disable_editor'))
  1332. {
  1333. add_filter( 'avf_builder_button_params', 'avia_woocommerce_disable_editor' );
  1334.  
  1335. function avia_woocommerce_disable_editor($params)
  1336. {
  1337. if(!current_theme_supports('avia_custom_shop_page'))
  1338. {
  1339. global $post_ID;
  1340. $shop_page_id = wc_get_page_id( 'shop' );
  1341.  
  1342. if($post_ID == $shop_page_id)
  1343. {
  1344. $disabled = __('(disabled)', 'avia_framework');
  1345.  
  1346. $params['visual_label'] = $params['visual_label'] . " ".$disabled;
  1347. $params['default_label'] = $params['default_label'] . " ".$disabled;
  1348. $params['button_class'] = "av-builer-button-disabled";
  1349. $params['disabled'] = true;
  1350. $params['note'] = __('This page is set as the default WooCommerce Shop Overview and therefore does not support the Enfold advanced layout editor', 'avia_framework')." <br/><a href='http://www.kriesi.at/documentation/enfold/custom-woocommerce-shop-overview/' target='_blank'>(".__('Learn more').")</a>";
  1351.  
  1352. }
  1353. }
  1354. return $params;
  1355. }
  1356.  
  1357. }
  1358.  
  1359. if(!function_exists('avia_woocommerce_disable_editor_option'))
  1360. {
  1361. add_filter( 'avf_builder_active', 'avia_woocommerce_disable_editor_option' , 10 , 2);
  1362.  
  1363. function avia_woocommerce_disable_editor_option($params, $post_id)
  1364. {
  1365. if(!current_theme_supports('avia_custom_shop_page'))
  1366. {
  1367. if($post_id == wc_get_page_id( 'shop' ))
  1368. {
  1369. $params = false;
  1370. }
  1371. }
  1372.  
  1373. return $params;
  1374. }
  1375.  
  1376. }
Advertisement
Add Comment
Please, Sign In to add comment