Advertisement
Guest User

Untitled

a guest
Jul 21st, 2020
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.69 KB | None | 0 0
  1. <?php
  2. /**
  3. * WooCommerce Integration
  4. * =======================
  5. *
  6. * @since < 4.0
  7. * @since 4.5.6 modifications for sorting integrations with WC 3.5.7 (backwards comp. with config-356.php)
  8. */
  9. if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
  10.  
  11.  
  12. function avia_woocommerce_enabled()
  13. {
  14. // if( !function_exists( 'wc_get_template_part' ) && class_exists( 'woocommerce' )) return "deprecated";
  15. if ( class_exists( 'WooCommerce' ) ){ return true; }
  16. return false;
  17. }
  18.  
  19. global $avia_config;
  20.  
  21. //product thumbnails
  22. $avia_config['imgSize']['shop_thumbnail'] = array('width'=>120, 'height'=>120);
  23. $avia_config['imgSize']['shop_catalog'] = array('width'=>450, 'height'=>450);
  24. $avia_config['imgSize']['shop_single'] = array('width'=>450, 'height'=>999, 'crop' => false);
  25.  
  26. avia_backend_add_thumbnail_size($avia_config);
  27.  
  28. include('admin-options.php');
  29. include('admin-import.php');
  30. include( 'woocommerce-mod-css-dynamic.php' );
  31.  
  32. add_theme_support( 'woocommerce' );
  33.  
  34.  
  35. function av_add_deprecated_notice()
  36. {
  37. echo '<div class="notice notice-error">';
  38. echo '<p>' . __('Attention! Please update WooCommerce to the latest version to properly display your products', 'avia_framework') . '</p>';
  39. echo '</div>';
  40. }
  41.  
  42.  
  43.  
  44. //check if the plugin is enabled, otherwise stop the script
  45. if(avia_woocommerce_enabled() !== true) {
  46.  
  47. if(avia_woocommerce_enabled() == "deprecated")
  48. {
  49. add_action('admin_notices', 'av_add_deprecated_notice');
  50. }
  51.  
  52. return false;
  53. }
  54.  
  55.  
  56. /**
  57. * Checks if WooCommerce version is >= $version
  58. *
  59. * @since < 4.0
  60. * @param string $version
  61. * @return boolean
  62. */
  63. function avia_woocommerce_version_check( $version )
  64. {
  65. global $woocommerce;
  66.  
  67. if( version_compare( $woocommerce->version, $version, ">=" ) )
  68. {
  69. return true;
  70. }
  71.  
  72. return false;
  73. }
  74.  
  75.  
  76.  
  77. //register my own styles, remove wootheme stylesheet
  78. if( ! is_admin() )
  79. {
  80. add_action( 'init', 'avia_woocommerce_register_assets' );
  81. }
  82.  
  83.  
  84.  
  85. /**
  86. * Wrapper function as WC deprecated function get_woocommerce_term_meta with 3.6
  87. *
  88. * @since 4.5.6.1
  89. * @param int $term_id
  90. * @param string $key
  91. * @param bool $single
  92. * @return mixed
  93. */
  94. function avia_get_woocommerce_term_meta( $term_id, $key, $single = true )
  95. {
  96. if( ! avia_woocommerce_version_check( '3.6' ) )
  97. {
  98. return get_woocommerce_term_meta( $term_id, $key, $single );
  99. }
  100.  
  101. return function_exists( 'get_term_meta' ) ? get_term_meta( $term_id, $key, $single ) : get_metadata( 'woocommerce_term', $term_id, $key, $single );
  102. }
  103.  
  104.  
  105. function avia_woocommerce_register_assets()
  106. {
  107. wp_enqueue_style( 'avia-woocommerce-css', AVIA_BASE_URL.'config-woocommerce/woocommerce-mod.css');
  108. if( version_compare( WC()->version, '2.7.0', '<' ) )
  109. {
  110. wp_enqueue_script( 'avia-woocommerce-js', AVIA_BASE_URL.'config-woocommerce/woocommerce-mod-v26.js', array('jquery'), 1, true);
  111. }
  112. else
  113. {
  114. wp_enqueue_script( 'avia-woocommerce-js', AVIA_BASE_URL.'config-woocommerce/woocommerce-mod.js', array('jquery'), 1, true);
  115. }
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. global $woocommerce;
  124.  
  125. if(version_compare($woocommerce->version, "2.1", "<"))
  126. {
  127. define('WOOCOMMERCE_USE_CSS', false);
  128. }
  129. else
  130. {
  131. add_filter( 'woocommerce_enqueue_styles', 'avia_woocommerce_enqueue_styles' );
  132. function avia_woocommerce_enqueue_styles($styles)
  133. {
  134. $styles = array();
  135. return $styles;
  136. }
  137. }
  138.  
  139.  
  140. if ( class_exists( 'WC_Bookings' ) )
  141. {
  142. require_once( 'config-woocommerce-bookings/config.php' ); //compatibility with woocommerce plugin
  143. }
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. ######################################################################
  153. # config
  154. ######################################################################
  155.  
  156. //add avia_framework config defaults
  157.  
  158. $avia_config['shop_overview_column'] = get_option('avia_woocommerce_column_count'); // columns for the overview page
  159. $avia_config['shop_overview_products']= get_option('avia_woocommerce_product_count'); // products for the overview page
  160.  
  161. $avia_config['shop_single_column'] = 4; // columns for related products and upsells
  162. $avia_config['shop_single_column_items'] = 4; // number of items for related products and upsells
  163. $avia_config['shop_overview_excerpt'] = false; // display excerpt
  164.  
  165. if(!$avia_config['shop_overview_column']) $avia_config['shop_overview_column'] = 3;
  166.  
  167. /**
  168. * Setup product gallery support depending on user settings and available WooCommerce galleries
  169. */
  170. if( ! function_exists( 'avia_woocommerce_product_gallery_support_setup' ) )
  171. {
  172. if ( did_action( 'woocommerce_init' ) )
  173. {
  174. avia_woocommerce_product_gallery_support_setup();
  175. }
  176. else
  177. {
  178. add_action( 'woocommerce_init', 'avia_woocommerce_product_gallery_support_setup', 10);
  179. }
  180.  
  181. function avia_woocommerce_product_gallery_support_setup()
  182. {
  183. if( ! avia_woocommerce_version_check( '3.0.0' ) )
  184. {
  185. return;
  186. }
  187.  
  188. $options = avia_get_option();
  189.  
  190. // Fallback, if options have not been saved
  191. if( ! array_key_exists( 'product_gallery', $options ) || ( 'wc_30_gallery' != $options['product_gallery'] ) )
  192. {
  193. $options['product_gallery'] = '';
  194. }
  195.  
  196. if( 'wc_30_gallery' == $options['product_gallery'] )
  197. {
  198. add_theme_support( 'wc-product-gallery-zoom' );
  199. // uncomment the following line if you want default WooCommerce lightbox - else Enfold lightbox will be used
  200. // add_theme_support( 'wc-product-gallery-lightbox' );
  201. add_theme_support( 'wc-product-gallery-slider' );
  202. add_theme_support( 'avia-wc-30-product-gallery-feature' );
  203. }
  204.  
  205. return;
  206. }
  207. }
  208.  
  209. ######################################################################
  210. # Allow to add WC structured data on template builder page
  211. ######################################################################
  212. #
  213.  
  214. add_action( 'get_footer', 'avia_activate_wc_structured_data', 10, 1 );
  215.  
  216.  
  217. if( ! function_exists( 'avia_activate_wc_structured_data' ) )
  218. {
  219. /**
  220. *
  221. * @param type $name
  222. */
  223. function avia_activate_wc_structured_data( $name )
  224. {
  225. global $product;
  226.  
  227. if( ! avia_woocommerce_version_check( '3.0.0') )
  228. {
  229. return;
  230. }
  231.  
  232. // Currently only on single product page with template builder required
  233. if( ! is_product() || ! $product instanceof WC_Product )
  234. {
  235. return;
  236. }
  237.  
  238. /**
  239. * Check necessary data in \woocommerce\includes\class-wc-structured-data.php
  240. */
  241. if( ! did_action( 'woocommerce_before_main_content' ) )
  242. {
  243. WC()->structured_data->generate_website_data();
  244. }
  245.  
  246. if( ! ( did_action( 'woocommerce_shop_loop' ) || did_action( 'woocommerce_single_product_summary' ) ) )
  247. {
  248. WC()->structured_data->generate_product_data();
  249. }
  250.  
  251. // not needed on single product page
  252. if( ! did_action( 'woocommerce_breadcrumb' ) )
  253. {
  254. // WC()->structured_data->generate_breadcrumblist_data();
  255. }
  256. if( ! did_action( 'woocommerce_review_meta' ) )
  257. {
  258. // WC()->structured_data->generate_review_data();
  259. }
  260. if( ! did_action( 'woocommerce_email_order_details' ) )
  261. {
  262. // WC()->structured_data->generate_order_data();
  263. }
  264. }
  265. }
  266.  
  267. ######################################################################
  268. # Create the correct template html structure
  269. ######################################################################
  270.  
  271. //remove woo defaults
  272. remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
  273. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
  274. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
  275. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
  276. remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
  277. remove_action( 'woocommerce_pagination', 'woocommerce_catalog_ordering', 20 );
  278. remove_action( 'woocommerce_pagination', 'woocommerce_pagination', 10 );
  279. remove_action( 'woocommerce_before_single_product', array($woocommerce, 'show_messages'), 10);
  280.  
  281.  
  282.  
  283. //add theme actions && filter
  284. add_action( 'woocommerce_after_shop_loop_item_title', 'avia_woocommerce_overview_excerpt', 10);
  285. add_filter( 'loop_shop_columns', 'avia_woocommerce_loop_columns');
  286. add_filter( 'loop_shop_per_page', 'avia_woocommerce_product_count' );
  287.  
  288. //single page adds
  289. add_action( 'avia_add_to_cart', 'woocommerce_template_single_add_to_cart', 30, 2 );
  290.  
  291.  
  292.  
  293. /*update woocommerce v2*/
  294.  
  295. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); /*remove result count above products*/
  296. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); /*remove woocommerce ordering dropdown*/
  297. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); //remove rating
  298. remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 ); //remove woo pagination
  299.  
  300.  
  301.  
  302. ######################################################################
  303. # FUNCTIONS
  304. ######################################################################
  305.  
  306. #
  307. # set the shop page id, otherwise avia_get_the_ID() can return a wrong id on the shop page
  308. #
  309. add_filter('avf_avia_get_the_ID','avia_set_shop_page_id', 10, 1);
  310. function avia_set_shop_page_id($id)
  311. {
  312. if(is_shop()) $id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
  313. return $id;
  314. }
  315.  
  316. #
  317. # removes the default post image from shop overview pages and replaces it with this image
  318. #
  319. add_action( 'woocommerce_before_shop_loop_item_title', 'avia_woocommerce_thumbnail', 10);
  320. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
  321.  
  322.  
  323.  
  324.  
  325. function avia_woocommerce_thumbnail($asdf)
  326. {
  327. global $product, $avia_config;
  328.  
  329. if(function_exists('wc_get_rating_html'))
  330. {
  331. $rating = wc_get_rating_html( $product->get_average_rating() );
  332. }
  333. else
  334. {
  335. $rating = $product->get_rating_html(); //get rating
  336. }
  337.  
  338. $id = get_the_ID();
  339. $size = 'shop_catalog';
  340.  
  341. echo "<div class='thumbnail_container'>";
  342. echo avia_woocommerce_gallery_first_thumbnail( $id , $size);
  343. echo get_the_post_thumbnail( $id , $size );
  344. if(!empty($rating)) echo "<span class='rating_container'>".$rating."</span>";
  345. if($product->get_type() == 'simple') echo "<span class='cart-loading'></span>";
  346. echo "</div>";
  347. }
  348.  
  349.  
  350. function avia_woocommerce_gallery_first_thumbnail($id, $size, $id_only = false)
  351. {
  352. $active_hover = get_post_meta( $id, '_product_hover', true );
  353.  
  354. if(!empty($active_hover))
  355. {
  356. $product_gallery = get_post_meta( $id, '_product_image_gallery', true );
  357.  
  358. if(!empty($product_gallery))
  359. {
  360. $gallery = explode(',',$product_gallery);
  361. $image_id = $gallery[0];
  362.  
  363. //return id only
  364. if(!empty($id_only)) return $image_id;
  365.  
  366. $image = wp_get_attachment_image( $image_id, $size, false, array( 'class' => "attachment-$size avia-product-hover" ));
  367.  
  368. //return image
  369. if(!empty($image)) return $image;
  370. }
  371. }
  372. }
  373.  
  374.  
  375.  
  376.  
  377. #
  378. # add ajax cart / options buttons to the product
  379. #
  380.  
  381. add_action( 'woocommerce_after_shop_loop_item', 'avia_add_cart_button', 16);
  382. function avia_add_cart_button()
  383. {
  384. global $product, $avia_config;
  385.  
  386. if ($product->get_type() == 'bundle' ){
  387. $product = new WC_Product_Bundle($product->get_id());
  388. }
  389.  
  390. $extraClass = "";
  391.  
  392. ob_start();
  393. woocommerce_template_loop_add_to_cart();
  394. $output = ob_get_clean();
  395.  
  396. if(!empty($output))
  397. {
  398. $pos = strpos($output, ">");
  399.  
  400. if ($pos !== false) {
  401. $output = substr_replace($output,"><span ".av_icon_string('cart')."></span> ", $pos , strlen(1));
  402. }
  403. }
  404.  
  405.  
  406. if($product->get_type() == 'variable' && empty($output))
  407. {
  408. $output = '<a class="add_to_cart_button button product_type_variable" href="'.get_permalink($product->get_id()).'"><span '.av_icon_string("details").'></span> '.__("Select options","avia_framework").'</a>';
  409. }
  410.  
  411. if(in_array($product->get_type(), array('subscription', 'simple', 'bundle')))
  412. {
  413. $output .= '<a class="button show_details_button" href="'.get_permalink($product->get_id()).'"><span '.av_icon_string("details").'></span> '.__("Show Details","avia_framework").'</a>';
  414. }
  415. else
  416. {
  417. $extraClass = "single_button";
  418. }
  419.  
  420. if(empty($extraClass)) $output .= " <span class='button-mini-delimiter'></span>";
  421.  
  422.  
  423. if($output && !post_password_required() && '' == avia_get_option('product_layout',''))
  424. {
  425. echo "<div class='avia_cart_buttons $extraClass'>$output</div>";
  426. }
  427. }
  428.  
  429.  
  430.  
  431.  
  432.  
  433. #
  434. # wrap products on overview pages into an extra div for improved styling options. adds "product_on_sale" class if prodct is on sale
  435. #
  436.  
  437. add_action( 'woocommerce_before_shop_loop_item', 'avia_shop_overview_extra_div', 5);
  438. function avia_shop_overview_extra_div()
  439. {
  440. global $product;
  441. $product_class = $product->is_on_sale() ? "product_on_sale" : "";
  442. $product_class.= " av-product-class-".avia_get_option('product_layout');
  443.  
  444. echo "<div class='inner_product main_color wrapped_style noLightbox $product_class'>";
  445. }
  446.  
  447. add_action( 'woocommerce_after_shop_loop_item', 'avia_close_div', 1000);
  448. function avia_close_div()
  449. {
  450. echo "</div>";
  451. }
  452.  
  453.  
  454. #
  455. # wrap product titles and sale number on overview pages into an extra div for improved styling options
  456. #
  457.  
  458. add_action( 'woocommerce_before_shop_loop_item_title', 'avia_shop_overview_extra_header_div', 20);
  459. function avia_shop_overview_extra_header_div()
  460. {
  461. echo "<div class='inner_product_header'><div class='avia-arrow'></div>";
  462. echo "<div class='inner_product_header_table'>";
  463. echo "<div class='inner_product_header_cell'>";
  464. }
  465.  
  466. add_action( 'woocommerce_after_shop_loop_item_title', 'avia_close_div', 1000);
  467. add_action( 'woocommerce_after_shop_loop_item_title', 'avia_close_div', 1001);
  468. add_action( 'woocommerce_after_shop_loop_item_title', 'avia_close_div', 1002);
  469.  
  470.  
  471. #
  472. # remove on sale badge from usual location and add it to the bottom of the product
  473. #
  474. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10);
  475. add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10);
  476.  
  477.  
  478. #
  479. # 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
  480. #
  481. function avia_shop_nav($args)
  482. {
  483. $output = "";
  484. $url = avia_collect_shop_urls();
  485.  
  486. $output .= "<ul>";
  487.  
  488. if( is_user_logged_in() )
  489. {
  490. $current = $sub1 = $sub2 = $sub3 = "";
  491. if(is_account_page()) $current = "current-menu-item";
  492. if(is_page(get_option('woocommerce_change_password_page_id'))) $sub1 = "current-menu-item";
  493. if(is_page(get_option('woocommerce_edit_address_page_id'))) $sub2 = "current-menu-item";
  494. if(is_page(get_option('woocommerce_view_order_page_id'))) $sub3 = "current-menu-item";
  495.  
  496.  
  497. $output .= "<li class='$current account_overview_link'><a href='".$url['account_overview']."'>".__('My Account', 'avia_framework')."</a>";
  498. $output .= "<ul>";
  499. $output .= "<li class='$sub1 account_change_pw_link'><a href='".$url['account_change_pw']."'>".__('Change Password', 'avia_framework')."</a></li>";
  500. $output .= "<li class='$sub2 account_edit_adress_link'><a href='".$url['account_edit_adress']."'>".__('Edit Address', 'avia_framework')."</a></li>";
  501. $output .= "<li class='$sub3 account_view_order_link'><a href='".$url['account_view_order']."'>".__('View Order', 'avia_framework')."</a></li>";
  502. $output .= "</ul>";
  503. $output .= "</li>";
  504. $output .= "<li class='account_logout_link'><a href='".$url['logout']."'>".__('Log Out', 'avia_framework')."</a></li>";
  505. }
  506. else
  507. {
  508. $sub1 = $sub2 = "";
  509. if(is_page(get_option('woocommerce_myaccount_page_id')))
  510. {
  511. if(isset($_GET['account_visible']) && $_GET['account_visible'] == 'register') $sub1 = "current-menu-item";
  512. if(isset($_GET['account_visible']) && $_GET['account_visible'] == 'login') $sub2 = "current-menu-item";
  513. }
  514.  
  515. $url_param = strpos($url['account_overview'], '?') === false ? "?" : "&";
  516.  
  517. if (get_option('woocommerce_enable_myaccount_registration') =='yes')
  518. {
  519. $output .= "<li class='register_link $sub1'><a href='".$url['account_overview'].$url_param."account_visible=register'>".__('Register', 'avia_framework')."</a></li>";
  520. }
  521.  
  522. $output .= "<li class='login_link $sub2'><a href='".$url['account_overview'].$url_param."account_visible=login'>".__('Log In', 'avia_framework')."</a></li>";
  523. }
  524.  
  525. $output .= "</ul>";
  526.  
  527. if($args['echo'] == true)
  528. {
  529. echo $output;
  530. }
  531. else
  532. {
  533. return $output;
  534. }
  535. }
  536.  
  537.  
  538. #
  539. # helper function that collects all the necessary urls for the shop navigation
  540. #
  541.  
  542. function avia_collect_shop_urls()
  543. {
  544. global $woocommerce;
  545.  
  546. $url['cart'] = $woocommerce->cart->get_cart_url();
  547. $url['checkout'] = $woocommerce->cart->get_checkout_url();
  548. $url['account_overview'] = get_permalink(get_option('woocommerce_myaccount_page_id'));
  549. $url['account_edit_adress'] = get_permalink(get_option('woocommerce_edit_address_page_id'));
  550. $url['account_view_order'] = get_permalink(get_option('woocommerce_view_order_page_id'));
  551. $url['account_change_pw'] = get_permalink(get_option('woocommerce_change_password_page_id'));
  552. $url['logout'] = wp_logout_url(home_url('/'));
  553.  
  554. return $url;
  555. }
  556.  
  557.  
  558.  
  559.  
  560. #
  561. # check which page is displayed and if the automatic sidebar menu for subpages should be prevented
  562. #
  563. add_filter( 'avf_sidebar_menu_filter', 'avia_woocommerce_sidebar_filter');
  564.  
  565. function avia_woocommerce_sidebar_filter($menu)
  566. {
  567. $id = avia_get_the_ID();
  568. if(is_cart() || is_checkout() || get_option('woocommerce_thanks_page_id') == $id){$menu = "";}
  569. return $menu;
  570. }
  571.  
  572.  
  573. #
  574. # check if a single product is displayed and always set the sidebar styling to that of a right sidebar
  575. #
  576. add_filter( 'avf_sidebar_position', 'avia_woocommerce_sidebar_pos');
  577.  
  578. function avia_woocommerce_sidebar_pos($sidebar)
  579. {
  580. if(is_product())
  581. {
  582. $sidebar = "sidebar_right";
  583. }
  584.  
  585. return $sidebar;
  586. }
  587.  
  588.  
  589.  
  590. function avia_add_to_cart($post, $product )
  591. {
  592. echo "<div class='avia_cart avia_cart_".$product->get_type()."'>";
  593. do_action( 'avia_add_to_cart', $post, $product );
  594. echo "</div>";
  595. }
  596.  
  597.  
  598.  
  599. #
  600. # replace thumbnail image size with full size image on single pages
  601. #
  602. /*
  603.  
  604. add_filter( 'single_product_small_thumbnail_size', 'avia_woocommerce_thumb_size');
  605.  
  606. function avia_woocommerce_thumb_size()
  607. {
  608. return 'shop_single';
  609. }
  610. */
  611.  
  612.  
  613.  
  614.  
  615. #
  616. # if we are viewing a woocommerce page modify the breadcrumb nav
  617. #
  618.  
  619. if(!function_exists('avia_woocommerce_breadcrumb'))
  620. {
  621. add_filter('avia_breadcrumbs_trail','avia_woocommerce_breadcrumb', 10, 2 );
  622.  
  623. function avia_woocommerce_breadcrumb( $trail, $args )
  624. {
  625. global $avia_config;
  626.  
  627. if(is_woocommerce())
  628. {
  629. $front_id = avia_get_option('frontpage');
  630. $home = isset( $trail[0] ) ? $trail[0] : '';
  631. $last = array_pop($trail);
  632. $shop_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
  633. $taxonomy = "product_cat";
  634.  
  635. // on the shop frontpage simply display the shop name, rather than shop name + "All Products"
  636. if(is_shop())
  637. {
  638. if(!empty($shop_id) && $shop_id != -1) $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
  639. $last = "";
  640.  
  641. if(is_search())
  642. {
  643. $last = __('Search results for:','avia_framework').' '.esc_attr($_GET['s']);
  644. }
  645. }
  646.  
  647. // on the product page single page modify the breadcrumb to read [home] [if available:parent shop pages] [shop] [if available:parent categories] [category] [title]
  648. if(is_product())
  649. {
  650. //fetch all product categories and search for the ones with parents. if none are avalaible use the first category found
  651. $product_category = $parent_cat = array();
  652. $temp_cats = get_the_terms(get_the_ID(), $taxonomy);
  653.  
  654. if( is_array( $temp_cats ) && ! empty( $temp_cats ) )
  655. {
  656. foreach( $temp_cats as $key => $cat )
  657. {
  658. if($cat->parent != 0 && !in_array($cat->term_taxonomy_id, $parent_cat))
  659. {
  660. $product_category[] = $cat;
  661. $parent_cat[] = $cat->parent;
  662. }
  663. }
  664.  
  665. //if no categories with parents use the first one
  666. if(empty($product_category)) $product_category[] = reset($temp_cats);
  667.  
  668. }
  669. //unset the trail and build our own
  670. unset($trail);
  671.  
  672. $trail = ( empty( $home ) ) ? array() : array( 0 => $home );
  673. if(!empty($shop_id) && $shop_id != -1) $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
  674. if(!empty($parent_cat)) $trail = array_merge( $trail, avia_breadcrumbs_get_term_parents( $parent_cat[0] , $taxonomy ) );
  675. 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>';
  676.  
  677. }
  678.  
  679.  
  680. // add the [shop] trail to category/tag pages: [home] [if available:parent shop pages] [shop] [if available:parent categories] [category/tag]
  681. if(is_product_category() || is_product_tag())
  682. {
  683. if(!empty($shop_id) && $shop_id != -1)
  684. {
  685. $shop_trail = avia_breadcrumbs_get_parents( $shop_id ) ;
  686. array_splice($trail, 1, 0, $shop_trail);
  687. }
  688. }
  689.  
  690. if(is_product_tag())
  691. {
  692. $last = __("Tag",'avia_framework').": ".$last;
  693. }
  694.  
  695. if( ! empty( $last ) )
  696. {
  697. $trail['trail_end'] = $last;
  698. }
  699.  
  700. /**
  701. * Allow to remove "Shop" in breadcrumb when shop page is frontpage
  702. *
  703. * @since 4.2.7
  704. */
  705. $trail_count = count( $trail );
  706. if( ( $front_id == $shop_id ) && ! empty( $home ) && ( $trail_count > 1 ) )
  707. {
  708. $hide = apply_filters( 'avf_woocommerce_breadcrumb_hide_shop', 'hide', $trail, $args );
  709. if( 'hide' == $hide )
  710. {
  711. $title = get_the_title( $shop_id );
  712.  
  713. for( $i = 1; $i < $trail_count; $i++ )
  714. {
  715. if( false !== strpos( $trail[ $i ], $title ) )
  716. {
  717. unset( $trail[ $i ] );
  718. break;
  719. }
  720. }
  721.  
  722. $trail = array_merge( $trail );
  723. }
  724. }
  725. }
  726.  
  727. return $trail;
  728. }
  729.  
  730. }
  731.  
  732.  
  733.  
  734. #
  735. # creates the avia framework container arround the shop pages
  736. #
  737. add_action( 'woocommerce_before_main_content', 'avia_woocommerce_before_main_content', 10);
  738.  
  739.  
  740. function avia_woocommerce_before_main_content()
  741. {
  742. global $avia_config;
  743.  
  744. if(!isset($avia_config['shop_overview_column'])) $avia_config['shop_overview_column'] = "auto";
  745.  
  746. $id = get_option('woocommerce_shop_page_id');
  747. $layout = get_post_meta($id, 'layout', true);
  748.  
  749. if(!empty($layout))
  750. {
  751. $avia_config['layout']['current'] = $avia_config['layout'][$layout];
  752. $avia_config['layout']['current']['main'] = $layout;
  753. }
  754.  
  755. $avia_config['layout'] = apply_filters('avia_layout_filter', $avia_config['layout'], $id);
  756.  
  757. $title_args = array();
  758.  
  759. if(is_woocommerce())
  760. {
  761. $t_link = "";
  762.  
  763. if(is_shop()) $title = get_option('woocommerce_shop_page_title');
  764.  
  765. $shop_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
  766. if($shop_id && $shop_id != -1)
  767. {
  768. if(empty($title)) $title = get_the_title($shop_id);
  769. $t_link = get_permalink($shop_id);
  770. }
  771.  
  772. if(empty($title)) $title = __("Shop",'avia_framework');
  773.  
  774. if(is_product_category() || is_product_tag())
  775. {
  776. global $wp_query;
  777. $tax = $wp_query->get_queried_object();
  778. $title = $tax->name;
  779. $t_link = '';
  780. }
  781.  
  782. $title_args = array('title' => $title, 'link' => $t_link);
  783. }
  784.  
  785. if( get_post_meta(get_the_ID(), 'header', true) != 'no') echo avia_title($title_args);
  786.  
  787.  
  788. if(is_singular()) {
  789.  
  790. $result = 'sidebar_right';
  791. $avia_config['layout']['current'] = $avia_config['layout'][$result];
  792. $avia_config['layout']['current']['main'] = $result;
  793.  
  794. }
  795. $sidebar_setting = avia_layout_class( 'main' , false );
  796. echo "<div class='container_wrap container_wrap_first main_color {$sidebar_setting} template-shop shop_columns_".$avia_config['shop_overview_column']."'>";
  797.  
  798. echo "<div class='container'>";
  799.  
  800. if(!is_singular()) { $avia_config['overview'] = true; }
  801. }
  802.  
  803. #
  804. # closes the avia framework container arround the shop pages
  805. #
  806.  
  807. add_action( 'woocommerce_after_main_content', 'avia_woocommerce_after_main_content', 10);
  808. function avia_woocommerce_after_main_content()
  809. {
  810.  
  811. global $avia_config;
  812. $avia_config['currently_viewing'] = "shop";
  813.  
  814. //reset all previous queries
  815. wp_reset_query();
  816.  
  817. //get the sidebar
  818. if(!is_singular())
  819. get_sidebar();
  820.  
  821. // echo "</div>"; // end container - gets already closed at the top of footer.php
  822.  
  823. echo "</div>"; // end tempate-shop content
  824. echo "</div>"; // close default .container_wrap element
  825. }
  826.  
  827.  
  828. add_action( 'avf_custom_sidebar', 'avia_woocommerce_custom_sidebar', 10);
  829. function avia_woocommerce_custom_sidebar($sidebar)
  830. {
  831. if(is_shop())
  832. {
  833. $the_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
  834. $sidebar = get_post_meta($the_id, 'sidebar', true);
  835. }
  836.  
  837. return $sidebar;
  838. }
  839.  
  840.  
  841.  
  842.  
  843. #
  844. # wrap an empty product search into extra div
  845. #
  846. add_action( 'woocommerce_before_main_content', 'avia_woocommerce_404_search', 9111);
  847. function avia_woocommerce_404_search()
  848. {
  849. global $wp_query;
  850.  
  851. if( (is_search() || is_archive()) && empty($wp_query->found_posts) )
  852. {
  853. echo "<div class='template-page template-search template-search-none content ".avia_layout_class( 'content', false )." units'>";
  854. echo "<div class='entry entry-content-wrapper' id='search-fail'>";
  855. }
  856. }
  857.  
  858. add_action( 'woocommerce_after_main_content', 'avia_woocommerce_404_search_close', 1);
  859. function avia_woocommerce_404_search_close()
  860. {
  861. global $wp_query;
  862.  
  863. if( (is_search() || is_shop() || is_archive()) && empty($wp_query->found_posts) )
  864. {
  865. get_template_part('includes/error404');
  866. echo "</div>";
  867. echo "</div>"; // close default .container_wrap element
  868. }
  869. }
  870.  
  871.  
  872.  
  873.  
  874. #
  875. # modifies the class of a page so we can display single login and single register
  876. #
  877. add_filter( 'avia_layout_class_filter_main', 'avia_register_login_class');
  878.  
  879. function avia_register_login_class($layout)
  880. {
  881. if(isset($_GET['account_visible']))
  882. {
  883. if($_GET['account_visible'] == 'register') $layout .= " template-register";
  884. if($_GET['account_visible'] == 'login') $layout .= " template-login";
  885. }
  886.  
  887. return $layout;
  888. }
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896. #
  897. # creates the avia framework content container arround the shop loop
  898. #
  899. add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_before_shop_loop', 1);
  900.  
  901. function avia_woocommerce_before_shop_loop()
  902. {
  903.  
  904. global $avia_config;
  905. if(isset($avia_config['dynamic_template'])) return;
  906. $markup = avia_markup_helper(array('context' => 'content','echo'=>false,'post_type'=>'products'));
  907. echo "<main class='template-shop content ".avia_layout_class( 'content' , false)." units' $markup><div class='entry-content-wrapper'>";
  908. }
  909.  
  910. #
  911. # closes the avia framework content container arround the shop loop
  912. #
  913. add_action( 'woocommerce_after_shop_loop', 'avia_woocommerce_after_shop_loop', 10);
  914.  
  915. function avia_woocommerce_after_shop_loop()
  916. {
  917. global $avia_config;
  918. if(isset($avia_config['dynamic_template'])) return;
  919. if(isset($avia_config['overview'] )) echo avia_pagination('', 'nav');
  920. echo "</div></main>"; //end content
  921. }
  922.  
  923.  
  924.  
  925. #
  926. # echo the excerpt
  927. #
  928. function avia_woocommerce_overview_excerpt()
  929. {
  930. global $avia_config;
  931.  
  932. if(!empty($avia_config['shop_overview_excerpt']))
  933. {
  934. echo "<div class='product_excerpt'>";
  935. the_excerpt();
  936. echo "</div>";
  937. }
  938. }
  939.  
  940.  
  941.  
  942. #
  943. # creates the preview images based on page/category image
  944. #
  945. remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
  946. remove_action( 'woocommerce_product_archive_description', 'woocommerce_product_archive_description', 10 );
  947.  
  948. add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_overview_banner_image', 10);
  949. add_action( 'woocommerce_before_shop_loop', 'woocommerce_taxonomy_archive_description', 11 );
  950. //add_action( 'woocommerce_before_shop_loop', 'woocommerce_product_archive_description', 12 ); //causes warning
  951.  
  952.  
  953. function avia_woocommerce_overview_banner_image()
  954. {
  955. global $avia_config;
  956. if(avia_is_dynamic_template() || is_paged() || is_search() ) return false;
  957.  
  958. $image_size = "entry_with_sidebar";
  959. $layout = avia_layout_class( 'main' , false );
  960. if($layout == 'fullsize') $image_size = 'entry_without_sidebar';
  961.  
  962. if(is_shop())
  963. {
  964. $shop_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
  965. if($shop_id != -1)
  966. {
  967. $image = get_the_post_thumbnail($shop_id, $image_size);
  968. if($image) echo "<div class='page-thumb'>{$image}</div>";
  969. }
  970. }
  971.  
  972.  
  973.  
  974. if(is_product_category())
  975. {
  976. global $wp_query;
  977. $image = "";
  978. if(isset($wp_query->query_vars['taxonomy']))
  979. {
  980. $term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']);
  981.  
  982. if(!empty($term->term_id))
  983. {
  984. $attachment_id = avia_get_woocommerce_term_meta($term->term_id, 'thumbnail_id');
  985. $style = avia_get_woocommerce_term_meta($term->term_id, 'av_cat_styling');
  986.  
  987. if(!empty($attachment_id) && empty($style))
  988. {
  989. $image = wp_get_attachment_image( $attachment_id, $image_size, false, array('class'=>'category_thumb'));
  990. if($image) echo "<div class='page-thumb'>{$image}</div>";
  991. }
  992.  
  993. }
  994. }
  995. }
  996.  
  997. }
  998.  
  999.  
  1000.  
  1001. add_action( 'ava_after_main_container', 'avia_woocommerce_big_cat_banner', 11 );
  1002.  
  1003.  
  1004. function avia_woocommerce_big_cat_banner()
  1005. {
  1006. if(is_product_category())
  1007. {
  1008. global $wp_query, $avia_config;
  1009.  
  1010. if(isset($wp_query->query_vars['taxonomy']))
  1011. {
  1012. $term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']);
  1013. if( ! empty( $term->term_id ) )
  1014. {
  1015. $description = term_description() ;
  1016. $style = avia_get_woocommerce_term_meta( $term->term_id, 'av_cat_styling' );
  1017. $attachment_id = avia_get_woocommerce_term_meta( $term->term_id, 'thumbnail_id' );
  1018.  
  1019. $overlay = avia_get_woocommerce_term_meta( $term->term_id, 'av-banner-overlay' );
  1020. $font = avia_get_woocommerce_term_meta( $term->term_id, 'av-banner-font' );
  1021. $opacity = avia_get_woocommerce_term_meta( $term->term_id, 'av-banner-overlay-opacity' );
  1022.  
  1023. if(!empty($style))
  1024. {
  1025. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_taxonomy_archive_description', 11 );
  1026. echo avia_woocommerce_parallax_banner($attachment_id, $overlay, $opacity, $description, $font);
  1027. $avia_config['woo-banner'] = true;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. }
  1033.  
  1034.  
  1035.  
  1036. add_action( 'ava_after_main_container', 'avia_woocommerce_shop_banner', 11 );
  1037.  
  1038. function avia_woocommerce_shop_banner()
  1039. {
  1040. global $avia_config;
  1041.  
  1042. if(is_shop() || (is_product_category() && avia_get_option('shop_banner_global') == "shop_banner_global") && !isset($avia_config['woo-banner']))
  1043. {
  1044. $options = avia_get_option();
  1045.  
  1046. if( isset( $options['shop_banner'] ) && ( $options['shop_banner'] == 'av-active-shop-banner' ) )
  1047. {
  1048. $bg = $options['shop_banner_image'];
  1049. $overlay = $options['shop_banner_overlay_color'];
  1050. $opacity = $options['shop_banner_overlay_opacity'];
  1051. $description= wpautop($options['shop_banner_message']);
  1052. $font = $options['shop_banner_message_color'];
  1053.  
  1054. echo avia_woocommerce_parallax_banner($bg, $overlay, $opacity, $description, $font);
  1055. }
  1056. }
  1057. }
  1058.  
  1059.  
  1060. function avia_woocommerce_parallax_banner( $bg, $overlay, $opacity, $description, $font )
  1061. {
  1062.  
  1063. if( is_numeric( $bg ) )
  1064. {
  1065. $bg = wp_get_attachment_image_src($bg, 'extra_large');
  1066. $bg = ( is_array( $bg ) && $bg[0] != '' ) ? $bg[0] : '';
  1067. }
  1068.  
  1069. if( $font )
  1070. {
  1071. $font = "style='color:{$font};'";
  1072. }
  1073.  
  1074. if( $bg )
  1075. {
  1076. $bg = "background-image: url(".$bg.");";
  1077. }
  1078.  
  1079. $output = '';
  1080.  
  1081. $output .='<div id="av_product_description" class="avia-section main_color avia-section-large avia-no-border-styling avia-full-stretch av-parallax-section av-section-color-overlay-active avia-bg-style-parallax container_wrap fullsize" data-section-bg-repeat="stretch" '.$font.'>';
  1082. $output .='<div class="av-parallax avia-full-stretch" data-avia-parallax-ratio="0.3">';
  1083. $output .='<div class="av-parallax-inner av-parallax-woo" style="'.$bg.' main_color background-attachment: scroll; background-position: 50% 50%; background-repeat: no-repeat;">';
  1084. $output .='</div>';
  1085. $output .='</div>';
  1086.  
  1087.  
  1088. $output .='<div class="av-section-color-overlay-wrap">';
  1089. if(!empty($overlay))
  1090. {
  1091. $output .='<div class="av-section-color-overlay" style="opacity: '.$opacity.'; background-color: '.$overlay.'; "></div>';
  1092. }
  1093.  
  1094. $output .='<div class="container">';
  1095. $output .='<main class="template-page content av-content-full alpha units">';
  1096. if($description) $output .= "<h1>".$description."</h1>";
  1097. $output .='</main></div></div></div>';
  1098.  
  1099. return $output;
  1100. }
  1101.  
  1102.  
  1103. #
  1104. # creates the title + description for overview pages
  1105. #
  1106. function avia_woocommerce_advanced_title()
  1107. {
  1108.  
  1109. global $wp_query;
  1110. $titleClass = "";
  1111. $image = "";
  1112.  
  1113.  
  1114. if(!empty($attachment_id))
  1115. {
  1116. $titleClass .= "title_container_image ";
  1117. $image = wp_get_attachment_image( $attachment_id, 'thumbnail', false, array('class'=>'category_thumb'));
  1118. }
  1119.  
  1120. echo "<div class='extralight-border title_container shop_title_container $titleClass'>";
  1121. //echo avia_breadcrumbs();
  1122. woocommerce_catalog_ordering();
  1123. echo $image;
  1124. }
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134. #
  1135. # modify shop overview column count
  1136. #
  1137. function avia_woocommerce_loop_columns()
  1138. {
  1139. global $avia_config;
  1140. return $avia_config['shop_overview_column'];
  1141. }
  1142.  
  1143.  
  1144. #
  1145. # modify shop overview product count
  1146. #
  1147.  
  1148. function avia_woocommerce_product_count()
  1149. {
  1150. global $avia_config;
  1151. return $avia_config['shop_overview_products'];
  1152. }
  1153.  
  1154.  
  1155. #
  1156. # filter cross sells on the cart page. display 4 on fullwidth pages and 3 on carts with sidebar
  1157. #
  1158.  
  1159. add_filter('woocommerce_cross_sells_total', 'avia_woocommerce_cross_sale_count');
  1160. add_filter('woocommerce_cross_sells_columns', 'avia_woocommerce_cross_sale_count');
  1161.  
  1162. function avia_woocommerce_cross_sale_count($count)
  1163. {
  1164. return 4;
  1165. }
  1166.  
  1167. #
  1168. # move cross sells below the shipping
  1169. #
  1170.  
  1171. remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
  1172. add_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display' , 10);
  1173.  
  1174.  
  1175.  
  1176.  
  1177. #
  1178. # display tabs and related items within the summary wrapper
  1179. #
  1180. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
  1181. add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 1 );
  1182.  
  1183.  
  1184.  
  1185. #
  1186. # display upsells and related products within dedicated div with different column and number of products
  1187. #
  1188. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products',20);
  1189. remove_action( 'woocommerce_after_single_product', 'woocommerce_output_related_products',10);
  1190. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_output_related_products', 20);
  1191.  
  1192. function avia_woocommerce_output_related_products($items = false, $columns = false)
  1193. {
  1194. global $avia_config;
  1195. $output = "";
  1196.  
  1197. if(!$items) $items = $avia_config['shop_single_column_items'];
  1198. if(!$columns) $columns = $avia_config['shop_single_column'];
  1199.  
  1200. ob_start();
  1201. woocommerce_related_products(array('posts_per_page'=>$items, 'columns'=>$columns)); // X products, X columns
  1202. $content = ob_get_clean();
  1203. if($content)
  1204. {
  1205. $output .= "<div class='product_column product_column_".$columns."'>";
  1206. //$output .= "<h3>".(__('Related Products', 'avia_framework'))."</h3>";
  1207. $output .= $content;
  1208. $output .= "</div>";
  1209. }
  1210.  
  1211. $avia_config['woo_related'] = $output;
  1212. return $output;
  1213.  
  1214. }
  1215.  
  1216. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
  1217. remove_action( 'woocommerce_after_single_product', 'woocommerce_upsell_display',10);
  1218. 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
  1219.  
  1220. function avia_woocommerce_output_upsells($items = false, $columns = false)
  1221. {
  1222. global $avia_config;
  1223.  
  1224. $output = "";
  1225.  
  1226. if(!$items) $items = $avia_config['shop_single_column_items'];
  1227. if(!$columns) $columns = $avia_config['shop_single_column'];
  1228.  
  1229. ob_start();
  1230. woocommerce_upsell_display($items,$columns); // 4 products, 4 columns
  1231. $content = ob_get_clean();
  1232. if($content)
  1233. {
  1234. $output .= "<div class='product_column product_column_".$columns."'>";
  1235. //$output .= "<h3>".(__('You may also like', 'avia_framework'))."</h3>";
  1236. $output .= $content;
  1237. $output .= "</div>";
  1238. }
  1239.  
  1240. $avia_config['woo_upsells'] = $output;
  1241. return $output;
  1242.  
  1243. }
  1244.  
  1245. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_display_output_upsells', 30); //display the related products and upsells
  1246.  
  1247. function avia_woocommerce_display_output_upsells()
  1248. {
  1249. global $avia_config;
  1250.  
  1251. $sells = isset( $avia_config['woo_upsells'] ) ? $avia_config['woo_upsells'] : '';
  1252. $related = isset( $avia_config['woo_related'] ) ? $avia_config['woo_related'] : '';
  1253.  
  1254. $products = $sells . $related;
  1255.  
  1256. if( ! empty( $products ) )
  1257. {
  1258.  
  1259. $output = "</div></div></div>";
  1260. $output .= '<div id="av_section_1" class="avia-section alternate_color avia-section-small container_wrap fullsize"><div class="container"><div class="template-page content twelve alpha units">';
  1261. $output .= $products;
  1262.  
  1263. echo $output;
  1264. }
  1265. }
  1266.  
  1267.  
  1268. if( ! function_exists( 'avia_before_get_sidebar_template_builder' ) && avia_woocommerce_enabled() )
  1269. {
  1270. /**
  1271. * Single Product page on ALB: we need to change sidebar - otherwise we have blog or page resulting in a wrong output
  1272. *
  1273. * @since 4.5.5
  1274. */
  1275. function avia_before_get_sidebar_template_builder()
  1276. {
  1277. global $avia_config;
  1278.  
  1279. if( is_product() )
  1280. {
  1281. $avia_config['currently_viewing'] = 'shop_single';
  1282. }
  1283. else if( is_page ( wc_get_page_id( 'shop' ) ) )
  1284. {
  1285. $avia_config['currently_viewing'] = 'shop';
  1286. }
  1287. }
  1288.  
  1289. add_action( 'ava_before_get_sidebar_template_builder', 'avia_before_get_sidebar_template_builder', 10 );
  1290. }
  1291.  
  1292.  
  1293. #
  1294. # wrap single product image in an extra div
  1295. #
  1296. add_action( 'woocommerce_before_single_product_summary', 'avia_add_image_div', 2);
  1297. add_action( 'woocommerce_before_single_product_summary', 'avia_close_image_div', 20);
  1298.  
  1299. if(!function_exists('avia_add_image_div'))
  1300. {
  1301. function avia_add_image_div()
  1302. {
  1303. $nolightbox = '';
  1304. $icon = '';
  1305.  
  1306. if( avia_woocommerce_version_check( '3.0.0' ) )
  1307. {
  1308. if( current_theme_supports( 'wc-product-gallery-lightbox' ) )
  1309. {
  1310. $nolightbox = 'noLightbox';
  1311. }
  1312. else if( current_theme_supports( 'avia-wc-30-product-gallery-feature' ) )
  1313. {
  1314. $nolightbox = 'noHover';
  1315. $icon = '<div class="avia-wc-30-product-gallery-lightbox" '.av_icon_string('search').' ></div>';
  1316. }
  1317. }
  1318.  
  1319. echo '<div class="' . $nolightbox . ' single-product-main-image alpha">' . $icon;
  1320. }
  1321. }
  1322.  
  1323.  
  1324.  
  1325. if(!function_exists('avia_close_image_div'))
  1326. {
  1327. function avia_close_image_div()
  1328. {
  1329. global $avia_config;
  1330. if(is_product()) {
  1331. $avia_config['currently_viewing'] = "shop_single";
  1332. get_sidebar();
  1333. }
  1334. echo "</div>";
  1335. }
  1336. }
  1337.  
  1338.  
  1339.  
  1340. #
  1341. # wrap single product summary in an extra div
  1342. #
  1343. add_action( 'woocommerce_before_single_product_summary', 'avia_add_summary_div', 25);
  1344. add_action( 'woocommerce_after_single_product_summary', 'avia_close_div', 3);
  1345.  
  1346. if(!function_exists('avia_add_summary_div'))
  1347. {
  1348. function avia_add_summary_div()
  1349. {
  1350. echo "<div class='single-product-summary'>";
  1351. }
  1352. }
  1353.  
  1354. //remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
  1355.  
  1356. if(avia_woocommerce_version_check('3.0.0')) // in woocommerce 3.0.0
  1357. {
  1358. add_action('woocommerce_product_thumbnails', 'avia_product_gallery_thumbnail_opener', 19);
  1359. add_action('woocommerce_product_thumbnails', 'avia_close_div', 21);
  1360. }
  1361.  
  1362. if(!function_exists('avia_product_gallery_thumbnail_opener'))
  1363. {
  1364. function avia_product_gallery_thumbnail_opener()
  1365. {
  1366. echo "<div class='thumbnails'>";
  1367. }
  1368. }
  1369.  
  1370.  
  1371. if( ! function_exists( 'avia_woocommerce_frontend_search_params' ) )
  1372. {
  1373. add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_frontend_search_params', 20 );
  1374.  
  1375. /**
  1376. * Displays a front end interface for modifying the shoplist query parameters like sorting order, product count etc
  1377. *
  1378. * @since < 4.0
  1379. */
  1380. function avia_woocommerce_frontend_search_params()
  1381. {
  1382. global $avia_config;
  1383.  
  1384. if( ! empty( $avia_config['woocommerce']['disable_sorting_options'] ) )
  1385. {
  1386. return;
  1387. }
  1388.  
  1389. $product_order['default'] = __( 'Default', 'avia_framework' );
  1390. $product_order['menu_order'] = __( 'Custom', 'avia_framework' );
  1391. $product_order['title'] = __( 'Name', 'avia_framework' );
  1392. $product_order['price'] = __( 'Price', 'avia_framework' );
  1393. $product_order['date'] = __( 'Date', 'avia_framework' );
  1394. $product_order['popularity'] = __( 'Popularity (sales)', 'avia_framework' );
  1395. $product_order['rating'] = __( 'Average rating', 'avia_framework' );
  1396. $product_order['relevance'] = __( 'Relevance', 'avia_framework' );
  1397. $product_order['rand'] = __( 'Random', 'avia_framework' );
  1398. $product_order['id'] = __( 'Product ID', 'avia_framework' );
  1399.  
  1400. /**
  1401. *
  1402. * @since 4.5.6.2
  1403. * @return array
  1404. */
  1405. $product_order = apply_filters( 'avf_wc_product_order_dropdown_frontend', $product_order );
  1406.  
  1407. $product_sort['asc'] = __( 'Click to order products ascending', 'avia_framework' );
  1408. $product_sort['desc'] = __( 'Click to order products descending', 'avia_framework' );
  1409.  
  1410. $per_page_string = __( 'Products per page', 'avia_framework' );
  1411.  
  1412.  
  1413. $per_page = get_option( 'avia_woocommerce_product_count' );
  1414. if( ! $per_page )
  1415. {
  1416. $per_page = get_option( 'posts_per_page' );
  1417. }
  1418.  
  1419. /**
  1420. * ALB elements can return all elements = -1
  1421. */
  1422. if( ! empty( $avia_config['woocommerce']['default_posts_per_page'] ) && is_numeric( $avia_config['woocommerce']['default_posts_per_page'] ) )
  1423. {
  1424. if( $avia_config['woocommerce']['default_posts_per_page'] > 0 )
  1425. {
  1426. $per_page = $avia_config['woocommerce']['default_posts_per_page'];
  1427. }
  1428. }
  1429.  
  1430. parse_str( $_SERVER['QUERY_STRING'], $params );
  1431.  
  1432.  
  1433. if( ! isset( $params['product_order'] ) )
  1434. {
  1435. $po_key = 'default';
  1436. }
  1437. else
  1438. {
  1439. $po_key = $params['product_order'];
  1440. }
  1441.  
  1442. if( ! isset( $params['product_sort'] ) )
  1443. {
  1444. $ps_key = ! empty( $avia_config['woocommerce']['product_sort'] ) ? $avia_config['woocommerce']['product_sort'] : 'asc';
  1445. }
  1446. else
  1447. {
  1448. $ps_key = $params['product_sort'];
  1449. }
  1450.  
  1451. if( 'default' == $po_key )
  1452. {
  1453. unset( $params['product_sort'] );
  1454. }
  1455.  
  1456. $params['avia_extended_shop_select'] = 'yes';
  1457.  
  1458. // $po_key = ! empty( $avia_config['woocommerce']['product_order'] ) ? $avia_config['woocommerce']['product_order'] : $params['product_order'];
  1459. // $ps_key = ! empty( $avia_config['woocommerce']['product_sort'] ) ? $avia_config['woocommerce']['product_sort'] : $params['product_sort'];
  1460. $pc_key = ! empty( $avia_config['woocommerce']['product_count'] ) ? $avia_config['woocommerce']['product_count'] : $per_page;
  1461.  
  1462. $ps_key = strtolower( $ps_key );
  1463.  
  1464. $show_sort = ! in_array( $po_key, array( 'rand', 'popularity', 'rating', 'default' ) );
  1465.  
  1466. $nofollow = 'rel="nofollow"';
  1467.  
  1468. //generate markup
  1469. $output = '';
  1470. $output .= "<div class='product-sorting'>";
  1471. $output .= "<ul class='sort-param sort-param-order'>";
  1472. $output .= "<li><span class='currently-selected'>" . __( 'Sort by', 'avia_framework' ) . " <strong>{$product_order[$po_key]}</strong></span>";
  1473. $output .= "<ul>";
  1474.  
  1475. foreach ( $product_order as $order_key => $order_text )
  1476. {
  1477. $query_string = 'default' == $order_key ? avia_woo_build_query_string( $params, 'product_order', $order_key, 'product_sort' ) : avia_woo_build_query_string( $params, 'product_order', $order_key );
  1478.  
  1479. $output .= '<li' . avia_woo_active_class( $po_key, $order_key ) . '>';
  1480. $output .= "<a href='{$query_string}' {$nofollow}>";
  1481. $output .= "<span class='avia-bullet'></span>{$order_text}";
  1482. $output .= '</a>';
  1483. $output .= '</li>';
  1484. }
  1485.  
  1486. $output .= '</ul>';
  1487. $output .= '</li>';
  1488. $output .= '</ul>';
  1489.  
  1490. if( $show_sort )
  1491. {
  1492. $output .= "<ul class='sort-param sort-param-sort'>";
  1493. $output .= '<li>';
  1494.  
  1495. if( $ps_key == 'desc' )
  1496. {
  1497. $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>";
  1498. }
  1499. if( $ps_key == 'asc' )
  1500. {
  1501. $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>";
  1502. }
  1503.  
  1504. $output .= '</li>';
  1505. $output .= '</ul>';
  1506. }
  1507.  
  1508. if( ! isset( $avia_config['woocommerce']['default_posts_per_page'] ) || ( $avia_config['woocommerce']['default_posts_per_page'] > 0 ) )
  1509. {
  1510. $output .= "<ul class='sort-param sort-param-count'>";
  1511. $output .= "<li><span class='currently-selected'>".__("Display",'avia_framework')." <strong>".$pc_key." ".$per_page_string."</strong></span>";
  1512. $output .= '<ul>';
  1513. $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>";
  1514. $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>";
  1515. $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>";
  1516. $output .= '</ul>';
  1517. $output .= '</li>';
  1518. $output .= '</ul>';
  1519. }
  1520.  
  1521.  
  1522. $output .= '</div>';
  1523. echo $output;
  1524. }
  1525. }
  1526.  
  1527.  
  1528. if( ! function_exists( 'avia_woocommerce_ajax_search_params' ) )
  1529. {
  1530. /**
  1531. * Add support for WC product display settings
  1532. *
  1533. * @since 4.7.3.1
  1534. * @param array $params
  1535. * @return array
  1536. */
  1537. function avia_woocommerce_ajax_search_params( $params = array() )
  1538. {
  1539. if( ! avia_woocommerce_enabled() )
  1540. {
  1541. return $params;
  1542. }
  1543.  
  1544. if( ! avia_woocommerce_version_check( '3.0.0') )
  1545. {
  1546. return $params;
  1547. }
  1548.  
  1549. /**
  1550. *
  1551. * @since 4.7.3.1
  1552. * @param string $visibility 'show'|'hide'|'' for WC default
  1553. * @param string $context
  1554. * @return string 'show'|'hide'|'' for WC default
  1555. */
  1556. $products_visibility = apply_filters( 'avf_ajax_search_woocommerce_params', '', 'out_of_stock' );
  1557.  
  1558. /**
  1559. *
  1560. * @since 4.7.3.1
  1561. * @param string $visibility 'show'|'hide'|'' for WC default
  1562. * @param string $context
  1563. * @return string 'show'|'hide'|'' for all
  1564. */
  1565. $prod_hidden = apply_filters( 'avf_ajax_search_woocommerce_params', '', 'hidden_products' );
  1566.  
  1567. /**
  1568. *
  1569. * @since 4.7.3.1
  1570. * @param string $visibility 'show'|'hide'|'' for WC default
  1571. * @param string $context
  1572. * @return string 'show'|'hide'|'' for all
  1573. */
  1574. $prod_featured = apply_filters( 'avf_ajax_search_woocommerce_params', '', 'featured_products' );
  1575.  
  1576. // Meta query - replaced by Tax query in WC 3.0.0
  1577. $meta_query = array();
  1578. $tax_query = array();
  1579.  
  1580. avia_wc_set_out_of_stock_query_params( $meta_query, $tax_query, $products_visibility );
  1581. avia_wc_set_hidden_prod_query_params( $meta_query, $tax_query, $prod_hidden );
  1582. avia_wc_set_featured_prod_query_params( $meta_query, $tax_query, $prod_featured );
  1583.  
  1584. if( empty( $tax_query ) )
  1585. {
  1586. return $params;
  1587. }
  1588.  
  1589. if( ! isset( $params['tax_query'] ) || ! is_array( $params['tax_query'] ) )
  1590. {
  1591. $params['tax_query'] = array();
  1592. }
  1593.  
  1594. foreach( $tax_query as $value )
  1595. {
  1596. $params['tax_query'][] = $value;
  1597. }
  1598.  
  1599. return $params;
  1600. }
  1601.  
  1602. add_filter( 'avf_ajax_search_query', 'avia_woocommerce_ajax_search_params', 20, 1 );
  1603. }
  1604.  
  1605.  
  1606. if( ! function_exists( 'avia_woo_active_class' ) )
  1607. {
  1608. /**
  1609. * Helper function to create the active list class
  1610. *
  1611. * @param string $key1
  1612. * @param string $key2
  1613. * @return string
  1614. */
  1615. function avia_woo_active_class( $key1, $key2 )
  1616. {
  1617. return ( $key1 == $key2 ) ? " class='current-param'" : '';
  1618. }
  1619. }
  1620.  
  1621.  
  1622. if( ! function_exists( 'avia_woo_build_query_string' ) )
  1623. {
  1624. /**
  1625. * helper function to build the query strings for the catalog ordering menu
  1626. *
  1627. * @since < 4.0
  1628. * @param array $params
  1629. * @param string $overwrite_key
  1630. * @param string $overwrite_value
  1631. * @param string $remove_key
  1632. * @return string
  1633. */
  1634. function avia_woo_build_query_string( $params = array(), $overwrite_key = '', $overwrite_value = '', $remove_key = '' )
  1635. {
  1636. if( ! empty( $overwrite_key ) )
  1637. {
  1638. $params[ $overwrite_key ] = $overwrite_value;
  1639. }
  1640.  
  1641. if( ! empty( $remove_key ) )
  1642. {
  1643. unset( $params[ $remove_key ] );
  1644. }
  1645.  
  1646. $paged = ( array_key_exists( 'product_count', $params ) ) ? 'paged=1&' : '';
  1647.  
  1648. return "?" . $paged . http_build_query( $params );
  1649. }
  1650. }
  1651.  
  1652.  
  1653. if( ! function_exists( 'avia_woocommerce_overwrite_catalog_ordering' ) )
  1654. {
  1655. add_action( 'woocommerce_get_catalog_ordering_args', 'avia_woocommerce_overwrite_catalog_ordering', 20, 1 );
  1656.  
  1657. /**
  1658. * Overwrite the query parameters from WooCommerce
  1659. *
  1660. * @since < 4.0
  1661. * @param array $args
  1662. * @return string
  1663. */
  1664. function avia_woocommerce_overwrite_catalog_ordering( $args )
  1665. {
  1666. global $avia_config;
  1667.  
  1668. if( empty( $avia_config['woocommerce'] ) )
  1669. {
  1670. $avia_config['woocommerce'] = array();
  1671. }
  1672.  
  1673. if( ! empty( $avia_config['woocommerce']['disable_sorting_options'] ) )
  1674. {
  1675. return $args;
  1676. }
  1677.  
  1678. /**
  1679. * WC added shortcodes that use this filter (e.g. products).
  1680. * We only need to alter the query when we have our select boxes.
  1681. *
  1682. * LINITATION: It is not possible to mix shop overview (= shop) and other shortcodes because we cannot distinguish when this filter is called !!!
  1683. */
  1684. if( ! isset( $_REQUEST['avia_extended_shop_select'] ) || ( 'yes' != $_REQUEST['avia_extended_shop_select'] ) )
  1685. {
  1686. $avia_config['woocommerce']['product_sort'] = strtolower( $args['order'] );
  1687. $avia_config['woocommerce']['product_order'] = strtolower( $args['orderby'] );
  1688.  
  1689. return $args;
  1690. }
  1691.  
  1692. //check the folllowing get parameters and session vars. if they are set overwrite the defaults
  1693. $check = array( 'product_order', 'product_count', 'product_sort' );
  1694.  
  1695. foreach( $check as $key )
  1696. {
  1697. if( isset( $_GET[ $key ] ) )
  1698. {
  1699. $_SESSION['avia_woocommerce'][ $key ] = esc_attr( $_GET[ $key ] );
  1700. }
  1701. if( isset( $_SESSION['avia_woocommerce'][ $key ] ) )
  1702. {
  1703. $avia_config['woocommerce'][ $key ] = $_SESSION['avia_woocommerce'][ $key ];
  1704. }
  1705. }
  1706.  
  1707. // if user wants to use new product order remove the old sorting parameter
  1708. if( isset( $_GET['product_order'] ) && ! isset( $_GET['product_sort'] ) && isset( $_SESSION['avia_woocommerce']['product_sort'] ) )
  1709. {
  1710. unset( $_SESSION['avia_woocommerce']['product_sort'], $avia_config['woocommerce']['product_sort'] );
  1711. }
  1712.  
  1713. $orderby = '';
  1714. $order = '';
  1715.  
  1716. /**
  1717. * Set the product sorting
  1718. */
  1719. $product_sort = '';
  1720. if( isset( $avia_config['woocommerce']['product_sort'] ) )
  1721. {
  1722. $product_sort = strtoupper( $avia_config['woocommerce']['product_sort'] );
  1723. switch ( $product_sort )
  1724. {
  1725. case 'DESC':
  1726. case 'ASC':
  1727. break;
  1728. default:
  1729. $product_sort = 'ASC';
  1730. break;
  1731. }
  1732. }
  1733.  
  1734. /**
  1735. * Set the product order with default sortings
  1736. */
  1737. $product_order = isset( $avia_config['woocommerce']['product_order'] ) ? $avia_config['woocommerce']['product_order'] :'';
  1738. switch ( $product_order )
  1739. {
  1740. case 'id':
  1741. case 'relevance':
  1742. case 'date':
  1743. $orderby = $product_order;
  1744. $order = ! empty( $product_sort ) ? $product_sort : 'DESC';
  1745. break;
  1746. case 'menu_order':
  1747. case 'title' :
  1748. case 'price' :
  1749. $orderby = $product_order;
  1750. $order = ! empty( $product_sort ) ? $product_sort : 'ASC';
  1751. break;
  1752. case 'rand':
  1753. case 'popularity':
  1754. case 'rating':
  1755. $orderby = $product_order;
  1756. break;
  1757. case 'default':
  1758. default:
  1759. $orderby = '';
  1760. break;
  1761. }
  1762.  
  1763. WC()->query->remove_ordering_args();
  1764.  
  1765. $old_disable_sorting_options = isset( $avia_config['woocommerce']['disable_sorting_options'] ) ? $avia_config['woocommerce']['disable_sorting_options'] : null;
  1766. $avia_config['woocommerce']['disable_sorting_options'] = true;
  1767.  
  1768. $new_args = WC()->query->get_catalog_ordering_args( $orderby, $order );
  1769.  
  1770. if( ! is_null( $old_disable_sorting_options) )
  1771. {
  1772. $avia_config['woocommerce']['disable_sorting_options'] = $old_disable_sorting_options;
  1773. }
  1774. else
  1775. {
  1776. unset( $avia_config['woocommerce']['disable_sorting_options'] );
  1777. }
  1778.  
  1779.  
  1780. /**
  1781. * set the product count
  1782. */
  1783. if( isset( $avia_config['woocommerce']['product_count'] ) && is_numeric( $avia_config['woocommerce']['product_count'] ) )
  1784. {
  1785. $avia_config['shop_overview_products_overwritten'] = true;
  1786. $avia_config['shop_overview_products'] = (int) $avia_config['woocommerce']['product_count'];
  1787. }
  1788.  
  1789. $avia_config['woocommerce']['product_order'] = strtolower( $new_args['orderby'] );
  1790. $avia_config['woocommerce']['product_sort'] = strtolower( $new_args['order'] );
  1791.  
  1792. return $new_args;
  1793. }
  1794.  
  1795.  
  1796. }
  1797.  
  1798. //remove produt information on password protected products
  1799. if(!function_exists('avia_woocommerce_remove_hooks'))
  1800. {
  1801. add_action('woocommerce_before_single_product', 'avia_woocommerce_remove_hooks');
  1802.  
  1803. function avia_woocommerce_remove_hooks()
  1804. {
  1805. /*remove content from password protected products*/
  1806. if(post_password_required())
  1807. {
  1808. add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_echo_password', 1 );
  1809. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 1 );
  1810. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
  1811. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
  1812. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
  1813. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
  1814. remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
  1815. remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
  1816. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
  1817. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
  1818. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  1819. remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
  1820. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
  1821. remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
  1822. remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
  1823. remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
  1824. remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
  1825. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
  1826. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
  1827. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
  1828. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
  1829. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
  1830. }
  1831. }
  1832. }
  1833.  
  1834. if(!function_exists('avia_woocommerce_echo_password'))
  1835. {
  1836. add_action('ava_woocomemrce_password_protection_remove_hooks', 'avia_woocommerce_remove_hooks');
  1837.  
  1838. function avia_woocommerce_echo_password()
  1839. {
  1840. /*remove content from password protected products*/
  1841. if(post_password_required())
  1842. {
  1843. echo get_the_password_form();
  1844. }
  1845. }
  1846. }
  1847.  
  1848. if( ! function_exists( 'avia_woocommerce_product_gallery_support' ) )
  1849. {
  1850. if ( did_action( 'woocommerce_init' ) )
  1851. {
  1852. avia_woocommerce_product_gallery_support();
  1853. }
  1854. else
  1855. {
  1856. add_action( 'woocommerce_init', 'avia_woocommerce_product_gallery_support', 50 );
  1857. }
  1858.  
  1859. function avia_woocommerce_product_gallery_support()
  1860. {
  1861. if( avia_woocommerce_version_check( '3.0.0' ) && current_theme_supports( 'avia-wc-30-product-gallery-feature' ) )
  1862. {
  1863. remove_action( 'woocommerce_product_thumbnails', 'avia_product_gallery_thumbnail_opener', 19 );
  1864. remove_action( 'woocommerce_product_thumbnails', 'avia_close_div', 21 );
  1865. }
  1866. else
  1867. {
  1868. add_filter( 'woocommerce_single_product_image_thumbnail_html','avia_woocommerce_gallery_thumbnail_description', 10, 4 );
  1869. }
  1870. }
  1871. }
  1872.  
  1873. /*
  1874. single page big image and thumbnails are using the same filter now. therefore we need to make sure that the images get the correct size by storing once the
  1875. woocommerce_product_thumbnails action has been called
  1876. */
  1877.  
  1878. add_action('woocommerce_product_thumbnails', 'avia_woocommerce_set_single_page_image_size');
  1879.  
  1880. if(!function_exists('avia_woocommerce_set_single_page_image_size'))
  1881. {
  1882. function avia_woocommerce_set_single_page_image_size()
  1883. {
  1884. global $avia_config;
  1885.  
  1886. if(!isset($avia_config['avwc-single-page-size']))
  1887. {
  1888. $avia_config['avwc-single-page-size'] = "shop_thumbnail";
  1889. }
  1890. }
  1891. }
  1892.  
  1893.  
  1894. if(!function_exists('avia_woocommerce_gallery_thumbnail_description'))
  1895. {
  1896. function avia_woocommerce_gallery_thumbnail_description($img, $attachment_id, $post_id = "", $image_class = "" )
  1897. {
  1898. global $avia_config;
  1899.  
  1900. $image_size = isset($avia_config['avwc-single-page-size']) ? $avia_config['avwc-single-page-size'] : 'shop_single';
  1901.  
  1902. $image_link = wp_get_attachment_url( $attachment_id );
  1903.  
  1904. if(!$image_link) return $img;
  1905.  
  1906. $image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', $image_size ) );
  1907. $image_title = esc_attr(get_post_field('post_content', $attachment_id));
  1908. $img = sprintf( '<a href="%s" class="%s" title="%s" rel="prettyPhoto[product-gallery]">%s</a>', $image_link, $image_class, $image_title, $image );
  1909.  
  1910. return $img;
  1911. }
  1912. }
  1913.  
  1914.  
  1915. if( ! function_exists( 'avia_title_args_woopage' ) )
  1916. {
  1917. add_filter( 'avf_title_args', 'avia_title_args_woopage', 10, 2 );
  1918.  
  1919. /**
  1920. *
  1921. * @param array $args
  1922. * @param int $id
  1923. * @return array
  1924. */
  1925. function avia_title_args_woopage( $args, $id )
  1926. {
  1927. if( is_single() && is_product() )
  1928. {
  1929. $args['heading'] = "strong";
  1930. }
  1931.  
  1932. return $args;
  1933. }
  1934. }
  1935.  
  1936.  
  1937. /*
  1938. Function that is able to overwrite the default "shop" page used by woocommerce so the template builder can be used
  1939. Will only be executed if the user has switched the "shop" page to advanced layout builder. Default products are no longer displayed
  1940. and the user needs to add a product grid element
  1941.  
  1942. Can be activated by adding
  1943.  
  1944. add_theme_support( 'avia_custom_shop_page' );
  1945.  
  1946. to your functions.php file
  1947. */
  1948. if(!function_exists('avia_woocommerce_default_page'))
  1949. {
  1950. add_filter( 'pre_get_posts', 'avia_woocommerce_default_page' );
  1951.  
  1952. function avia_woocommerce_default_page($query)
  1953. {
  1954. if(current_theme_supports('avia_custom_shop_page'))
  1955. {
  1956. if( isset( $_REQUEST['s'] ) )
  1957. {
  1958. return $query;
  1959. }
  1960.  
  1961. if(!$query->is_admin && $query->is_main_query() && !$query->is_tax && $query->is_archive && $query->is_post_type_archive)
  1962. {
  1963. $vars = $query->query_vars;
  1964.  
  1965. if(isset($vars['post_type']) && 'product' == $vars['post_type'] )
  1966. {
  1967. $shop_page_id = wc_get_page_id( 'shop' );
  1968. $builder_active = Avia_Builder()->get_alb_builder_status($shop_page_id);
  1969.  
  1970. if($builder_active == "active")
  1971. {
  1972. $query->set( 'post_type', 'page' );
  1973. $query->set( 'p', $shop_page_id );
  1974. $query->set( 'meta_query', array() );
  1975.  
  1976. $query->is_singular = true;
  1977. $query->is_page = true;
  1978. $query->is_archive = false;
  1979. $query->is_post_type_archive = false;
  1980. $query->query = array('p'=>$shop_page_id, 'post_type' => 'page');
  1981. }
  1982. }
  1983. }
  1984. }
  1985.  
  1986. return $query;
  1987.  
  1988. }
  1989. }
  1990.  
  1991.  
  1992.  
  1993. if(!function_exists('avia_woocommerce_disable_editor'))
  1994. {
  1995. add_filter( 'avf_builder_button_params', 'avia_woocommerce_disable_editor' );
  1996.  
  1997.  
  1998. function avia_woocommerce_disable_editor($params)
  1999. {
  2000. if(!current_theme_supports('avia_custom_shop_page'))
  2001. {
  2002. global $post_ID;
  2003. $shop_page_id = wc_get_page_id( 'shop' );
  2004.  
  2005. if($post_ID == $shop_page_id)
  2006. {
  2007. $disabled = __('(disabled)', 'avia_framework');
  2008.  
  2009. $params['visual_label'] = $params['visual_label'] . " ".$disabled;
  2010. $params['default_label'] = $params['default_label'] . " ".$disabled;
  2011. $params['button_class'] = "av-builer-button-disabled";
  2012. $params['disabled'] = true;
  2013. $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='https://kriesi.at/documentation/enfold/custom-woocommerce-shop-overview/' target='_blank' rel='noopener noreferrer'>(".__('Learn more').")</a>";
  2014.  
  2015. }
  2016. }
  2017.  
  2018.  
  2019. if(avia_backend_get_post_type() == "product")
  2020. {
  2021. $params['noteclass'] = "av-notice av-only-active";
  2022. $params['note'] = __('Please note that the Advanced Layout Builder for products will not work with all WooCommerce Extensions', 'avia_framework');
  2023. }
  2024.  
  2025.  
  2026.  
  2027.  
  2028. return $params;
  2029. }
  2030.  
  2031. }
  2032.  
  2033. if(!function_exists('avia_woocommerce_disable_editor_option'))
  2034. {
  2035. add_filter( 'avf_builder_active', 'avia_woocommerce_disable_editor_option' , 10 , 2);
  2036.  
  2037. function avia_woocommerce_disable_editor_option($params, $post_id)
  2038. {
  2039. if(!current_theme_supports('avia_custom_shop_page'))
  2040. {
  2041. if($post_id == wc_get_page_id( 'shop' ))
  2042. {
  2043. $params = false;
  2044. }
  2045. }
  2046.  
  2047. return $params;
  2048. }
  2049.  
  2050. }
  2051.  
  2052.  
  2053.  
  2054.  
  2055.  
  2056.  
  2057. #
  2058. # place the cart button according to the header layout (top/sidebar)
  2059. #
  2060.  
  2061. if(!function_exists('avia_woocommerce_cart_placement'))
  2062. {
  2063. add_action( 'init', 'avia_woocommerce_cart_placement', 10);
  2064.  
  2065. function avia_woocommerce_cart_placement()
  2066. {
  2067. $position = avia_get_option('header_position', 'header_top') == "header_top" ? "ava_main_header" : "ava_inside_main_menu";
  2068. if(avia_get_option('cart_icon') == "always_display_menu")
  2069. {
  2070. $position = "ava_inside_main_menu";
  2071. if( strpos( avia_get_option('header_layout'), 'bottom_nav_header') !== false && avia_get_option('header_position') == 'header_top')
  2072. {
  2073. $position = "ava_before_bottom_main_menu";
  2074. }
  2075. }
  2076.  
  2077. add_action( $position, 'avia_woocommerce_cart_dropdown', 10);
  2078. }
  2079. }
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086. #
  2087. # permanent display of cart button
  2088. #
  2089.  
  2090.  
  2091.  
  2092. if(!function_exists('avia_woocommerce_cart_pos'))
  2093. {
  2094. add_filter( 'avf_header_classes', 'avia_woocommerce_cart_pos' , 10 , 3);
  2095.  
  2096. function avia_woocommerce_cart_pos($class, $necessary, $prefix)
  2097. {
  2098. if($prefix == 'html_') // only for the html tag
  2099. {
  2100. global $woocommerce;
  2101. $cart = $woocommerce->cart->get_cart();
  2102. $cart_pos = avia_get_option('cart_icon');
  2103.  
  2104. if( $cart_pos == "always_display" || ( ! empty( $cart ) ) )
  2105. {
  2106. $class[] = "visible_cart";
  2107. }
  2108.  
  2109. if($cart_pos == "always_display_menu")
  2110. {
  2111. $class[] = "cart_at_menu";
  2112. }
  2113. }
  2114.  
  2115. return $class;
  2116. }
  2117.  
  2118. }
  2119.  
  2120.  
  2121.  
  2122. function avia_woocommerce_cart_dropdown()
  2123. {
  2124. global $woocommerce, $avia_config;
  2125. $cart_subtotal = $woocommerce->cart->get_cart_subtotal();
  2126. $link = function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : $woocommerce->cart->get_cart_url();
  2127. $id = "";
  2128. $added = wc_get_notices('success');
  2129. $trigger = !empty($added) ? "av-display-cart-on-load" : "";
  2130.  
  2131. if(avia_get_option('cart_icon') == "always_display_menu")
  2132. {
  2133. $id = 'id="menu-item-shop"';
  2134. }
  2135.  
  2136. $output = "";
  2137. $output .= "<ul {$id} class = 'menu-item cart_dropdown {$trigger}' data-success='".__('was added to the cart', 'avia_framework')."'><li class='cart_dropdown_first'>";
  2138. $output .= "<a class='cart_dropdown_link' href='".$link."'><span ".av_icon_string('cart')."></span><span class='av-cart-counter'>".WC()->cart->get_cart_contents_count()."</span><span class='avia_hidden_link_text'>".__('Shopping Cart','avia_framework')."</span></a><!--<span class='cart_subtotal'>".$cart_subtotal."</span>-->";
  2139. $output .= "<div class='dropdown_widget dropdown_widget_cart'><div class='avia-arrow'></div>";
  2140. $output .= '<div class="widget_shopping_cart_content"></div>';
  2141. $output .= "</div>";
  2142. $output .= "</li></ul>";
  2143.  
  2144.  
  2145. echo $output;
  2146.  
  2147. }
  2148.  
  2149. /*
  2150. after importing demo pages make sure that if we got multiple shop/my account/etc pages (happens if the user used default woocommerce setup)
  2151. to remove the duplicates and set the theme options properly
  2152. */
  2153.  
  2154. add_action('avia_after_import_hook', 'avia_woocommerce_set_pages');
  2155. // add_action('ava_after_main_container', 'avia_woocommerce_set_pages');
  2156.  
  2157. function avia_woocommerce_set_pages()
  2158. {
  2159. global $wpdb;
  2160.  
  2161. $pages = array(
  2162. 'shop' => array(
  2163. 'title' => 'Shop',
  2164. 'slug' => 'shop',
  2165. ),
  2166. 'cart' => array(
  2167. 'title' => 'Cart',
  2168. 'slug' => 'cart',
  2169. ),
  2170. 'checkout' => array(
  2171. 'title' => 'Checkout',
  2172. 'slug' => 'checkout',
  2173. ),
  2174. 'myaccount' => array(
  2175. 'title' => 'My Account',
  2176. 'slug' => 'my-account',
  2177. )
  2178. );
  2179.  
  2180. /*query string to get multiple posts with the same name*/
  2181. $pagequery = "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='page'";
  2182.  
  2183.  
  2184. foreach ($pages as $page)
  2185. {
  2186. $entries = $wpdb->get_results( $wpdb->prepare( $pagequery , $page['title'] ));
  2187.  
  2188. if(!empty($entries))
  2189. {
  2190. $keep = 0;
  2191. $delete = array();
  2192.  
  2193. //we got one post of that name. the user did not yet activate woocommerce setup or no page with that name was imported
  2194. if(count($entries) === 1)
  2195. {
  2196. $keep = $entries[0]->ID;
  2197. }
  2198. else //we got 2 or more entries. keep the one with the highest id as woocommerce setting and delete the other ones
  2199. {
  2200. foreach($entries as $entry)
  2201. {
  2202. if($entry->ID > $keep)
  2203. {
  2204. if($keep) $delete[] = $keep;
  2205. $keep = $entry->ID;
  2206. }
  2207. else
  2208. {
  2209. $delete[] = $entry->ID;
  2210. }
  2211. }
  2212. }
  2213.  
  2214. //delete the not required posts
  2215. foreach($delete as $delete_id)
  2216. {
  2217. wp_delete_post( $delete_id, true );
  2218. }
  2219.  
  2220. if($keep > 0)
  2221. {
  2222. //store the value of the $keep as the default woo setting
  2223. $setting = str_replace("-", "", $page['slug']);
  2224. update_option('woocommerce_' . $setting . '_page_id' , $keep);
  2225.  
  2226. //modify the page slug and remove any numbers if necessary
  2227. $update_post = array(
  2228. 'ID' => $keep,
  2229. 'post_name' => $page['slug']
  2230. );
  2231.  
  2232. wp_update_post( $update_post );
  2233. }
  2234. }
  2235. }
  2236. }
  2237.  
  2238. /**
  2239. * Helper functions for template builder elements - Product grids, slideshows, ......
  2240. * ==================================================================================
  2241. *
  2242. */
  2243. if( ! function_exists( 'avia_wc_set_out_of_stock_query_params' ) )
  2244. {
  2245.  
  2246. /**
  2247. * Returns the query parameters for the "product out of stock" feature for selecting the products
  2248. *
  2249. * @param array $meta_query
  2250. * @param array $tax_query
  2251. * @param string $products_visibility 'show'|'hide'|'' for WC default
  2252. */
  2253. function avia_wc_set_out_of_stock_query_params( array &$meta_query, array &$tax_query, $products_visibility = '' )
  2254. {
  2255. /**
  2256. * Backwards compatibility WC < 3.0.0
  2257. */
  2258. if( ! avia_woocommerce_version_check( '3.0.0') )
  2259. {
  2260. $meta_query[] = WC()->query->visibility_meta_query();
  2261. $meta_query[] = WC()->query->stock_status_meta_query();
  2262. $meta_query = array_filter( $meta_query );
  2263. }
  2264. else
  2265. {
  2266. switch( $products_visibility )
  2267. {
  2268. case 'show':
  2269. $hide = 'no';
  2270. break;
  2271. case 'hide':
  2272. $hide = 'yes';
  2273. break;
  2274. default:
  2275. $hide = get_option( 'woocommerce_hide_out_of_stock_items', 'no' );
  2276. }
  2277.  
  2278. if( 'yes' == $hide )
  2279. {
  2280. $outofstock_term = get_term_by( 'name', 'outofstock', 'product_visibility' );
  2281. if( $outofstock_term instanceof WP_Term )
  2282. {
  2283. $tax_query[] = array(
  2284. 'taxonomy' => 'product_visibility',
  2285. 'field' => 'term_taxonomy_id',
  2286. 'terms' => array( $outofstock_term->term_taxonomy_id ),
  2287. 'operator' => 'NOT IN'
  2288. );
  2289. }
  2290. }
  2291. }
  2292. }
  2293. }
  2294.  
  2295. if( ! function_exists( 'avia_wc_set_hidden_prod_query_params' ) )
  2296. {
  2297. /**
  2298. * Returns the query parameters for the catalog visibility "hidden" feature for selecting the products.
  2299. *
  2300. * @since 4.1.3
  2301. * @param array $meta_query
  2302. * @param array $tax_query
  2303. * @param string $catalog_visibility 'show'|'hide'|'' for all
  2304. */
  2305. function avia_wc_set_hidden_prod_query_params( array &$meta_query, array &$tax_query, $catalog_visibility = '' )
  2306. {
  2307. if( avia_woocommerce_version_check( '3.0.0') )
  2308. {
  2309. switch( $catalog_visibility )
  2310. {
  2311. case 'show':
  2312. $operator = 'IN';
  2313. break;
  2314. case 'hide':
  2315. $operator = 'NOT IN';
  2316. break;
  2317. default:
  2318. $operator = '';
  2319. }
  2320.  
  2321. if( in_array( $operator, array( 'IN', 'NOT IN' ) ) )
  2322. {
  2323. $hidden_term = get_term_by( 'name', 'exclude-from-catalog', 'product_visibility' );
  2324. if( $hidden_term instanceof WP_Term )
  2325. {
  2326. $tax_query[] = array(
  2327. 'taxonomy' => 'product_visibility',
  2328. 'field' => 'term_taxonomy_id',
  2329. 'terms' => array( $hidden_term->term_taxonomy_id ),
  2330. 'operator' => $operator
  2331. );
  2332. }
  2333. }
  2334. }
  2335. }
  2336. }
  2337.  
  2338. if( ! function_exists( 'avia_wc_set_featured_prod_query_params' ) )
  2339. {
  2340. /**
  2341. * Returns the query parameters for the catalog visibility "hidden" feature for selecting the products.
  2342. *
  2343. * @since 4.1.3
  2344. * @param array $meta_query
  2345. * @param array $tax_query
  2346. * @param string $catalog_visibility 'show'|'hide'|'' for all
  2347. */
  2348. function avia_wc_set_featured_prod_query_params( array &$meta_query, array &$tax_query, $catalog_visibility = '' )
  2349. {
  2350. if( avia_woocommerce_version_check( '3.0.0') )
  2351. {
  2352. switch( $catalog_visibility )
  2353. {
  2354. case 'show':
  2355. $operator = 'IN';
  2356. break;
  2357. case 'hide':
  2358. $operator = 'NOT IN';
  2359. break;
  2360. default:
  2361. $operator = '';
  2362. }
  2363.  
  2364. if( in_array( $operator, array( 'IN', 'NOT IN' ) ) )
  2365. {
  2366. $featured_term = get_term_by( 'name', 'featured', 'product_visibility' );
  2367. if( $featured_term instanceof WP_Term )
  2368. {
  2369. $tax_query[] = array(
  2370. 'taxonomy' => 'product_visibility',
  2371. 'field' => 'term_taxonomy_id',
  2372. 'terms' => array( $featured_term->term_taxonomy_id ),
  2373. 'operator' => $operator
  2374. );
  2375. }
  2376. }
  2377. }
  2378. }
  2379. }
  2380.  
  2381. if( ! function_exists( 'avia_wc_set_additional_filter_args' ) )
  2382. {
  2383. /**
  2384. * Add additional filters from user selections in widget like
  2385. * - minimum / maximum price filter
  2386. *
  2387. * @since 4.5.5
  2388. * @param array $meta_query
  2389. * @param array $tax_query
  2390. */
  2391. function avia_wc_set_additional_filter_args( array &$meta_query, array &$tax_query )
  2392. {
  2393. /**
  2394. * Filter for Minimum / Maximum Price
  2395. */
  2396. $args = array();
  2397. if( isset( $_REQUEST['min_price'] ) && is_numeric( $_REQUEST['min_price'] ) )
  2398. {
  2399. $args['min_price'] = $_REQUEST['min_price'];
  2400. }
  2401. if( isset( $_REQUEST['max_price'] ) && is_numeric( $_REQUEST['max_price'] ) )
  2402. {
  2403. $args['max_price'] = $_REQUEST['max_price'];
  2404. }
  2405.  
  2406. if( ! empty( $args ) )
  2407. {
  2408. $meta_query[] = wc_get_min_max_price_meta_query( $args );
  2409. }
  2410.  
  2411. /**
  2412. * Additional filters - see woocommerce\includes\class-wc-query.php::get_tax_query()
  2413. * ==================
  2414. */
  2415. $product_visibility_terms = wc_get_product_visibility_term_ids();
  2416. $product_visibility_not_in = array( is_search() && $main_query ? $product_visibility_terms['exclude-from-search'] : $product_visibility_terms['exclude-from-catalog'] );
  2417.  
  2418. /**
  2419. * Filter for rating
  2420. */
  2421. if ( isset( $_REQUEST['rating_filter'] ) )
  2422. {
  2423. $rating_filter = array_filter( array_map( 'absint', explode( ',', $_REQUEST['rating_filter'] ) ) );
  2424. $rating_terms = array();
  2425. for ( $i = 1; $i <= 5; $i ++ )
  2426. {
  2427. if ( in_array( $i, $rating_filter, true ) && isset( $product_visibility_terms[ 'rated-' . $i ] ) )
  2428. {
  2429. $rating_terms[] = $product_visibility_terms[ 'rated-' . $i ];
  2430. }
  2431. }
  2432. if ( ! empty( $rating_terms ) )
  2433. {
  2434. $tax_query[] = array(
  2435. 'taxonomy' => 'product_visibility',
  2436. 'field' => 'term_taxonomy_id',
  2437. 'terms' => $rating_terms,
  2438. 'operator' => 'IN',
  2439. 'rating_filter' => true,
  2440. );
  2441. }
  2442. }
  2443.  
  2444. /**
  2445. * Filter for additional attribute filters
  2446. */
  2447. $layered_nav_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
  2448. foreach ( $layered_nav_chosen_attributes as $taxonomy => $data )
  2449. {
  2450. $tax_query[] = array(
  2451. 'taxonomy' => $taxonomy,
  2452. 'field' => 'slug',
  2453. 'terms' => $data['terms'],
  2454. 'operator' => 'and' === $data['query_type'] ? 'AND' : 'IN',
  2455. 'include_children' => false,
  2456. );
  2457. }
  2458. }
  2459. }
  2460.  
  2461.  
  2462. if( ! function_exists( 'avia_wc_get_product_query_order_args' ) )
  2463. {
  2464. /**
  2465. * Returns the ordering args, either the default catalog settings or the user selected.
  2466. * Calls standard WC function to set filter hooks for order by
  2467. * and removes previously set filter hooks
  2468. *
  2469. * @since < 4.0
  2470. * @modified 4.5.6
  2471. * @param string $order_by
  2472. * @param string $order
  2473. * @return array
  2474. */
  2475. function avia_wc_get_product_query_order_args( $order_by = '', $order = '' )
  2476. {
  2477. $def_orderby = avia_wc_get_default_catalog_order_by();
  2478.  
  2479. $order_by = empty( $order_by ) ? $def_orderby['orderby'] : $order_by;
  2480. $order = empty( $order ) ? $def_orderby['order'] : $order;
  2481.  
  2482. // remove and set filter hooks !!
  2483. WC()->query->remove_ordering_args();
  2484. $ordering_args = WC()->query->get_catalog_ordering_args( $order_by, $order );
  2485.  
  2486. return $ordering_args;
  2487. }
  2488. }
  2489.  
  2490.  
  2491. if( ! function_exists( 'avia_wc_get_default_catalog_order_by' ) )
  2492. {
  2493. /**
  2494. * Returns the default settings for catalog order by and clears any set filter hook by this function
  2495. *
  2496. * ATTENTION: Though WC sets $order to ASC by default we replace it DESC as e.g. "most recent" retrurns ASC what is wrong (added with 4.5.6.1)
  2497. * =========
  2498. *
  2499. *
  2500. * @return array
  2501. */
  2502. function avia_wc_get_default_catalog_order_by()
  2503. {
  2504. // does not always return correct values !!!
  2505. // $args = WC()->query->get_catalog_ordering_args();
  2506.  
  2507. $orderby_value = apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
  2508.  
  2509. // Get order + orderby args from string
  2510. $orderby_value = explode( '-', $orderby_value );
  2511. $orderby = esc_attr( $orderby_value[0] );
  2512. $order = ! empty( $orderby_value[1] ) ? $orderby_value[1] : 'DESC';
  2513.  
  2514. $args = array();
  2515.  
  2516. $args['orderby'] = strtolower( $orderby );
  2517. $args['order'] = ( 'DESC' === strtoupper( $order ) ) ? 'DESC' : 'ASC';
  2518. $args['meta_key'] = '';
  2519.  
  2520. return $args;
  2521. }
  2522. }
  2523.  
  2524.  
  2525. if( ! function_exists( 'avia_wc_clear_catalog_ordering_args_filters' ) )
  2526. {
  2527. /**
  2528. * Remove all filters set by a call to WC()->query->get_catalog_ordering_args();
  2529. */
  2530. function avia_wc_clear_catalog_ordering_args_filters()
  2531. {
  2532. WC()->query->remove_ordering_args();
  2533. }
  2534. }
  2535.  
  2536.  
  2537.  
  2538. add_filter( 'woocommerce_product_is_visible', 'avia_wc_product_is_visible', 10, 2 );
  2539. if( ! function_exists( 'avia_wc_product_is_visible' ) )
  2540. {
  2541. /**
  2542. * Allows to change the default visibility for products in catalog.
  2543. *
  2544. * WC checks this in the loop when showing products on a catalog page - as we allow user to show/hide products out of stock in various
  2545. * builder elements we have to force the display even if visibility is false
  2546. *
  2547. * @param boolean $visible
  2548. * @param int $product_id
  2549. * @return boolean
  2550. */
  2551. function avia_wc_product_is_visible( $visible, $product_id )
  2552. {
  2553. global $avia_config;
  2554.  
  2555. if( ! isset( $avia_config['woocommerce']['catalog_product_visibility'] ) )
  2556. {
  2557. return $visible;
  2558. }
  2559.  
  2560. switch( $avia_config['woocommerce']['catalog_product_visibility'] )
  2561. {
  2562. case 'show_all':
  2563. return true;
  2564. case 'hide_out_of_stock':
  2565. $product = wc_get_product( $product_id );
  2566. if( ! $product instanceof WC_Product )
  2567. {
  2568. return $visible;
  2569. }
  2570. return $product->is_in_stock();
  2571. case 'use_default':
  2572. default:
  2573. return $visible;
  2574. }
  2575. }
  2576. }
  2577.  
  2578.  
  2579. if( ! function_exists( 'avia_wc_remove_inline_terms' ) )
  2580. {
  2581.  
  2582. /**
  2583. * If a template builder page with a fullwidth el is used for terms and conditions the terms and conditions are not displayed properly. we need to filter that.
  2584. * in case the user uses a template builder page do not display the inline terms. returning an empty string will just show the link to the TOS page
  2585. */
  2586. add_filter('woocommerce_format_content', 'avia_wc_remove_inline_terms', 10, 2);
  2587.  
  2588. function avia_wc_remove_inline_terms( $apply_filters, $raw_string )
  2589. {
  2590. if( is_checkout() ) {
  2591.  
  2592. $id = wc_get_page_id( 'terms' );
  2593.  
  2594. if(get_post_meta($id, '_aviaLayoutBuilder_active', true) == "active")
  2595. {
  2596. return '';
  2597. }
  2598. }
  2599.  
  2600. return $apply_filters;
  2601. }
  2602. }
  2603.  
  2604.  
  2605. add_filter( 'woocommerce_get_settings_checkout' , 'avia_wc_filter_terms_page_selection', 10 , 2);
  2606.  
  2607.  
  2608. if( ! function_exists( 'avia_wc_filter_terms_page_selection' ) )
  2609. {
  2610. /**
  2611. * Filter the content description for TOS page selection
  2612. */
  2613. function avia_wc_filter_terms_page_selection($settings)
  2614. {
  2615. foreach($settings as $key => $setting)
  2616. {
  2617. if( isset( $setting['id'] ) && ( $setting['id'] == "woocommerce_terms_page_id" ) )
  2618. {
  2619. $settings[$key]['desc'] .= "<br><br>".__('Attention! Pages built with the Enfold Advanced Template Builder will not be displayed at the bottom of the checkout page but only with a link.', 'avia_framework');
  2620. break;
  2621. }
  2622. }
  2623.  
  2624. return $settings;
  2625. }
  2626. }
  2627.  
  2628. /**
  2629. * Force WC images in widgets to have Enfold default image size
  2630. *
  2631. * @since 4.4.2
  2632. * @added_by Günter
  2633. */
  2634. add_action( 'woocommerce_widget_product_item_start', 'avia_wc_widget_product_item_start', 10, 1 );
  2635. add_filter( 'woocommerce_product_get_image', 'avia_wc_widget_product_image_size', 10, 6 );
  2636. add_action( 'woocommerce_widget_product_item_end', 'avia_wc_widget_product_item_end', 10, 1 );
  2637.  
  2638. global $avia_wc_product_widget_active;
  2639. $avia_wc_product_widget_active = false;
  2640.  
  2641. if( ! function_exists( 'avia_wc_widget_product_item_start' ) )
  2642. {
  2643. /**
  2644. * Set a global variable to limit changeing to widget areas only
  2645. *
  2646. * @since 4.4.2
  2647. * @added_by Günter
  2648. * @param array $args
  2649. * @return array
  2650. */
  2651. function avia_wc_widget_product_item_start( $args )
  2652. {
  2653. global $avia_wc_product_widget_active;
  2654.  
  2655. /**
  2656. * @since 4.4.2
  2657. * @return boolean
  2658. */
  2659. if( false !== apply_filters( 'avf_wc_widget_product_image_size_ignore', false, $args ) )
  2660. {
  2661. return;
  2662. }
  2663.  
  2664. $avia_wc_product_widget_active = true;
  2665. }
  2666. }
  2667.  
  2668. if( ! function_exists( 'avia_wc_widget_product_image_size' ) )
  2669. {
  2670. /**
  2671. * Modify default WC behaviour.
  2672. * Based on the function WC_Product::get_image
  2673. *
  2674. * @since 4.4.2
  2675. * @param string $image
  2676. * @param WC_Product $product
  2677. * @param string $size
  2678. * @param array $attr
  2679. * @param boolean $placeholder
  2680. * @param string $image1
  2681. * @return string
  2682. */
  2683. function avia_wc_widget_product_image_size( $image, $product, $size, $attr, $placeholder, $image1 )
  2684. {
  2685. global $avia_wc_product_widget_active, $avia_config;
  2686.  
  2687. if( ! $avia_wc_product_widget_active )
  2688. {
  2689. return $image;
  2690. }
  2691.  
  2692. /**
  2693. * @since 4.4.2
  2694. * @return string
  2695. */
  2696. $size = apply_filters( 'avf_wc_widget_product_image_size', 'widget', $product, $size, $attr, $placeholder );
  2697.  
  2698. if ( has_post_thumbnail( $product->get_id() ) )
  2699. {
  2700. $image = get_the_post_thumbnail( $product->get_id(), $size, $attr );
  2701. }
  2702. elseif ( ( $parent_id = wp_get_post_parent_id( $product->get_id() ) ) && has_post_thumbnail( $parent_id ) ) // @phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
  2703. {
  2704. $image = get_the_post_thumbnail( $parent_id, $size, $attr );
  2705. }
  2706. elseif ( $placeholder )
  2707. {
  2708. $image = wc_placeholder_img( $size );
  2709. }
  2710. else
  2711. {
  2712. $image = '';
  2713. }
  2714.  
  2715. return $image;
  2716. }
  2717. }
  2718.  
  2719. if( ! function_exists( 'avia_wc_widget_product_item_end' ) )
  2720. {
  2721. /**
  2722. * Reset a global variable to limit changeing to widget areas only
  2723. *
  2724. * @since 4.4.2
  2725. * @param array $args
  2726. */
  2727. function avia_wc_widget_product_item_end( $args )
  2728. {
  2729. global $avia_wc_product_widget_active;
  2730.  
  2731. $avia_wc_product_widget_active = false;
  2732. }
  2733. }
  2734.  
  2735.  
  2736. /**
  2737. * Fix problem with ALB pages used as "Terms and Conditions" page on checkout.
  2738. * WC loads page content above the checkbox with js. With ALB this breaks and might also lead to styling problems.
  2739. * Therefore we link to an external page.
  2740. *
  2741. * Up to WC 3.4.5 no hooks are provided to fix this in php. Therefore we have to add a js snippet.
  2742. *
  2743. * @since 4.4.2
  2744. * @added_by Günter
  2745. */
  2746. if( ! is_admin() && avia_woocommerce_version_check( '3.4.0' ) )
  2747. {
  2748. add_action( 'woocommerce_checkout_terms_and_conditions', 'avia_wc_checkout_terms_and_conditions' );
  2749.  
  2750. if( ! function_exists( 'avia_wc_checkout_terms_and_conditions' ) )
  2751. {
  2752. function avia_wc_checkout_terms_and_conditions()
  2753. {
  2754. $terms_id = wc_get_page_id('terms');
  2755. if( 'active' == Avia_Builder()->get_alb_builder_status( $terms_id ) )
  2756. {
  2757. add_action( 'wp_footer', 'avia_woocommerce_fix_checkout_term_link' );
  2758. }
  2759. }
  2760. }
  2761. if( ! function_exists( 'avia_woocommerce_fix_checkout_term_link' ) )
  2762. {
  2763. function avia_woocommerce_fix_checkout_term_link()
  2764. {
  2765. $i = 1;
  2766. ?>
  2767. <script>
  2768. (function($) {
  2769. // wait until everything completely loaded all assets
  2770. $(window).on('load', function() {
  2771. // remove the click event
  2772. $( document.body ).off( 'click', 'a.woocommerce-terms-and-conditions-link' );
  2773. });
  2774. }(jQuery));
  2775. </script>
  2776. <?php
  2777. }
  2778. }
  2779.  
  2780. }
  2781.  
  2782. if( ! function_exists( 'avia_woocommerce_shortcode_current_post' ) )
  2783. {
  2784.  
  2785. /**
  2786. * Shop page might have another query for products and global $post might be a product
  2787. *
  2788. * @since 4.5.6
  2789. * @param null|WP_Post $current_post
  2790. * @return null|WP_Post
  2791. */
  2792. function avia_woocommerce_shortcode_current_post( $current_post )
  2793. {
  2794. if( ! avia_woocommerce_enabled() )
  2795. {
  2796. return $current_post;
  2797. }
  2798.  
  2799. if( ! is_shop() )
  2800. {
  2801. return $current_post;
  2802. }
  2803.  
  2804. $post = get_post( wc_get_page_id( 'shop' ) );
  2805.  
  2806. return $post;
  2807. }
  2808.  
  2809. add_filter( 'avf_shortcode_handler_prepare_current_post', 'avia_woocommerce_shortcode_current_post', 10, 1 );
  2810. }
  2811.  
  2812.  
  2813. add_filter( 'woocommerce_add_to_cart_fragments', 'wc_mini_cart_refresh_number');
  2814. function wc_mini_cart_refresh_number($fragments){
  2815. ob_start();
  2816. $count = WC()->cart->get_cart_contents_count();
  2817. ?>
  2818. <div class="av-cart-counter <?php if($count) echo 'av-active-counter'; ?>">
  2819. <?php echo $count; ?>
  2820. </div>
  2821. <?php
  2822. $fragments['.av-cart-counter'] = ob_get_clean();
  2823. return $fragments;
  2824. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement