Advertisement
Guest User

Untitled

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