Advertisement
Guest User

Untitled

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