Advertisement
Guest User

functions

a guest
Dec 12th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 50.19 KB | None | 0 0
  1. <?php if ( ! defined( 'WOODMART_THEME_DIR' ) ) {
  2.     exit( 'No direct script access allowed' );
  3. }
  4.  
  5. /**
  6.  * ------------------------------------------------------------------------------------------------
  7.  * Main loop
  8.  * ------------------------------------------------------------------------------------------------
  9.  */
  10.  
  11. if( ! function_exists( 'woodmart_woocommerce_main_loop' ) ) {
  12.  
  13.     add_action( 'woodmart_woocommerce_main_loop', 'woodmart_woocommerce_main_loop' );
  14.  
  15.     function woodmart_woocommerce_main_loop( $fragments = false ) {
  16.         global $paged, $wp_query;
  17.  
  18.         $max_page = $wp_query->max_num_pages;
  19.  
  20.         if ( $fragments ) ob_start();
  21.        
  22.         if ( $fragments && isset( $_GET['loop'] ) ) woodmart_set_loop_prop( 'woocommerce_loop', (int) sanitize_text_field( $_GET['loop'] ) );
  23.        
  24.         if ( woocommerce_product_loop() ) : ?>
  25.            
  26.             <?php if( ! $fragments ) woocommerce_product_loop_start(); ?>
  27.            
  28.             <?php if ( wc_get_loop_prop( 'total' ) || $fragments ): ?>
  29.                 <?php while ( have_posts() ) : the_post(); ?>
  30.                    
  31.                     <?php
  32.                     /**
  33.                      * Hook: woocommerce_shop_loop.
  34.                      *
  35.                      * @hooked WC_Structured_Data::generate_product_data() - 10
  36.                      */
  37.                     do_action( 'woocommerce_shop_loop' );?>
  38.  
  39.                     <?php wc_get_template_part( 'content', 'product' ); ?>
  40.  
  41.                 <?php endwhile; // end of the loop. ?>
  42.             <?php endif; ?>
  43.            
  44.  
  45.             <?php if( ! $fragments ) woocommerce_product_loop_end(); ?>
  46.  
  47.             <?php
  48.                 /**
  49.                  * woocommerce_after_shop_loop hook
  50.                  *
  51.                  * @hooked woocommerce_pagination - 10
  52.                  */
  53.                 if( ! $fragments ) do_action( 'woocommerce_after_shop_loop' );
  54.             ?>
  55.  
  56.         <?php else: ?>
  57.            
  58.             <?php
  59.             /**
  60.              * Hook: woocommerce_no_products_found.
  61.              *
  62.              * @hooked wc_no_products_found - 10
  63.              */
  64.             do_action( 'woocommerce_no_products_found' ); ?>
  65.  
  66.         <?php endif;
  67.  
  68.         if ( $fragments ) $output = ob_get_clean();
  69.  
  70.         if( $fragments ) {
  71.             $output =  array(
  72.                 'items' => $output,
  73.                 'status' => ( $max_page > $paged ) ? 'have-posts' : 'no-more-posts',
  74.                 'nextPage' => str_replace( '&#038;', '&', next_posts( $max_page, false ) )
  75.             );
  76.  
  77.             echo json_encode( $output );
  78.         }
  79.     }
  80. }
  81. /**
  82.  * ------------------------------------------------------------------------------------------------
  83.  * Change number of products displayed per page
  84.  * ------------------------------------------------------------------------------------------------
  85.  */
  86.  
  87. if( ! function_exists( 'woodmart_shop_products_per_page' ) ) {
  88.     function woodmart_shop_products_per_page() {
  89.         $per_page = 12;
  90.         $number = apply_filters('woodmart_shop_per_page', woodmart_get_products_per_page() );
  91.         if( is_numeric( $number ) ) {
  92.             $per_page = $number;
  93.         }
  94.         return $per_page;
  95.     }
  96.  
  97.     add_filter( 'loop_shop_per_page', 'woodmart_shop_products_per_page', 20 );
  98. }
  99.  
  100. /**
  101.  * ------------------------------------------------------------------------------------------------
  102.  * Set full width layouts for woocommerce pages on set up
  103.  * ------------------------------------------------------------------------------------------------
  104.  */
  105.  
  106. if( ! function_exists( 'woodmart_woocommerce_install_actions' ) ) {
  107.     function woodmart_woocommerce_install_actions() {
  108.         if ( isset( $_GET['page'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wc-setup' && isset( $_GET['step'] ) && ! empty( $_GET['step'] ) && $_GET['step'] == 'next_steps') {
  109.             $pages = apply_filters( 'woocommerce_create_pages', array(
  110.                 'cart' => array(
  111.                     'name'    => _x( 'cart', 'Page slug', 'woodmart' ),
  112.                     'title'   => _x( 'Cart', 'Page title', 'woodmart' ),
  113.                     'content' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']'
  114.                 ),
  115.                 'checkout' => array(
  116.                     'name'    => _x( 'checkout', 'Page slug', 'woodmart' ),
  117.                     'title'   => _x( 'Checkout', 'Page title', 'woodmart' ),
  118.                     'content' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']'
  119.                 ),
  120.             ) );
  121.  
  122.             foreach ( $pages as $key => $page ) {
  123.                 $option = 'woocommerce_' . $key . '_page_id';
  124.                 $page_id = get_option( $option );
  125.                 update_post_meta( $page_id, '_woodmart_main_layout', 'full-width' );
  126.             }
  127.  
  128.             woodmart_woocommerce_image_dimensions();
  129.         }
  130.     }
  131.  
  132.     add_action( 'admin_init', 'woodmart_woocommerce_install_actions', 1000);
  133.     add_action( 'admin_print_styles', 'woodmart_woocommerce_install_actions', 1000);
  134. }
  135.  
  136. /**
  137.  * Define image sizes
  138.  */
  139. if( ! function_exists( 'woodmart_woocommerce_image_dimensions' ) ) {
  140.     function woodmart_woocommerce_image_dimensions() {
  141.         global $pagenow;
  142.      
  143.         update_option( 'woocommerce_single_image_width', '1200' );      // Single product image
  144.         update_option( 'woocommerce_thumbnail_image_width', '600' );    // Gallery and catalog image
  145.     }
  146. }
  147.  
  148. /**
  149.  * ------------------------------------------------------------------------------------------------
  150.  * Get base shop page link
  151.  * ------------------------------------------------------------------------------------------------
  152.  */
  153.  
  154. if( ! function_exists( 'woodmart_shop_page_link' ) ) {
  155.     function woodmart_shop_page_link( $keep_query = false, $taxonomy = '' ) {
  156.         // Base Link decided by current page
  157.         if ( woodmart_is_shop_on_front() ) {
  158.             $link = home_url();
  159.         } elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id('shop') ) ) {
  160.             $link = get_post_type_archive_link( 'product' );
  161.         } elseif( is_product_category() ) {
  162.             $link = get_term_link( get_query_var('product_cat'), 'product_cat' );
  163.         } elseif( is_product_tag() ) {
  164.             $link = get_term_link( get_query_var('product_tag'), 'product_tag' );
  165.         } else {
  166.             $link = get_term_link( get_query_var('term'), get_query_var('taxonomy') );
  167.         }
  168.  
  169.         if( $keep_query ) {
  170.  
  171.             // Min/Max
  172.             if ( isset( $_GET['min_price'] ) ) {
  173.                 $link = add_query_arg( 'min_price', wc_clean( $_GET['min_price'] ), $link );
  174.             }
  175.  
  176.             if ( isset( $_GET['max_price'] ) ) {
  177.                 $link = add_query_arg( 'max_price', wc_clean( $_GET['max_price'] ), $link );
  178.             }
  179.  
  180.             // Orderby
  181.             if ( isset( $_GET['orderby'] ) ) {
  182.                 $link = add_query_arg( 'orderby', wc_clean( $_GET['orderby'] ), $link );
  183.             }
  184.  
  185.             /**
  186.              * Search Arg.
  187.              * To support quote characters, first they are decoded from &quot; entities, then URL encoded.
  188.              */
  189.             if ( get_search_query() ) {
  190.                 $link = add_query_arg( 's', rawurlencode( wp_specialchars_decode( get_search_query() ) ), $link );
  191.             }
  192.  
  193.             // Post Type Arg
  194.             if ( isset( $_GET['post_type'] ) ) {
  195.                 $link = add_query_arg( 'post_type', wc_clean( $_GET['post_type'] ), $link );
  196.             }
  197.  
  198.             // Min Rating Arg
  199.             if ( isset( $_GET['min_rating'] ) ) {
  200.                 $link = add_query_arg( 'min_rating', wc_clean( $_GET['min_rating'] ), $link );
  201.             }
  202.  
  203.             // All current filters
  204.             if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) {
  205.                 foreach ( $_chosen_attributes as $name => $data ) {
  206.                     if ( $name === $taxonomy ) {
  207.                         continue;
  208.                     }
  209.                     $filter_name = sanitize_title( str_replace( 'pa_', '', $name ) );
  210.                     if ( ! empty( $data['terms'] ) ) {
  211.                         $link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
  212.                     }
  213.                     if ( 'or' == $data['query_type'] ) {
  214.                         $link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
  215.                     }
  216.                 }
  217.             }
  218.         }
  219.  
  220.         if ( is_string( $link ) ) {
  221.             return $link;
  222.         } else {
  223.             return '';
  224.         }
  225.     }
  226. }
  227.  
  228. /**
  229.  * ------------------------------------------------------------------------------------------------
  230.  * Get product design option
  231.  * ------------------------------------------------------------------------------------------------
  232.  */
  233.  
  234. if ( ! function_exists( 'woodmart_product_design' ) ) {
  235.     function woodmart_product_design() {
  236.         $design = woodmart_get_opt( 'product_design' );
  237.         if( is_singular( 'product' ) ) {
  238.             $custom = get_post_meta( get_the_ID(), '_woodmart_product_design', true );
  239.             if( ! empty( $custom ) && $custom != 'inherit' ) $design = $custom;
  240.         }
  241.  
  242.         return $design;
  243.     }
  244. }
  245.  
  246. /**
  247.  * ------------------------------------------------------------------------------------------------
  248.  * Is product sticky
  249.  * ------------------------------------------------------------------------------------------------
  250.  */
  251.  
  252. if ( ! function_exists( 'woodmart_product_sticky' ) ) {
  253.     function woodmart_product_sticky() {
  254.         $sticky = woodmart_get_opt( 'product_sticky' ) && in_array( woodmart_get_opt( 'single_product_style' ), array( 1, 2, 3 ) ) ? true : false;
  255.         if( is_singular( 'product' ) ) {
  256.             $custom = get_post_meta( get_the_ID(), '_woodmart_product_sticky', true );
  257.             if( ! empty( $custom ) && $custom != 'inherit' ) $sticky = $custom;
  258.         }
  259.  
  260.         return $sticky;
  261.     }
  262. }
  263.  
  264. /**
  265.  * ------------------------------------------------------------------------------------------------
  266.  * Register new image size two times larger than standard woocommerce one
  267.  * ------------------------------------------------------------------------------------------------
  268.  */
  269.  
  270. if( ! function_exists( 'woodmart_add_image_size' ) ) {
  271.     add_action( 'after_setup_theme', 'woodmart_add_image_size' );
  272.    
  273.     function woodmart_add_image_size() {
  274.        
  275.         if( ! function_exists( 'wc_get_image_size' ) ) return;
  276.        
  277.         $shop_catalog = wc_get_image_size( 'woocommerce_thumbnail' );
  278.        
  279.         $width = (int) ( $shop_catalog['width'] * 2 );
  280.         $height = ( !empty( $shop_catalog['height'] ) ) ? (int) ( $shop_catalog['height'] * 2 ) : '';
  281.        
  282.         add_image_size( 'woodmart_shop_catalog_x2', $width, $height, $shop_catalog['crop'] );
  283.     }
  284. }
  285.  
  286. /**
  287.  * ------------------------------------------------------------------------------------------------
  288.  * Custom thumbnail function for slider
  289.  * ------------------------------------------------------------------------------------------------
  290.  */
  291.  
  292. if ( ! function_exists( 'woodmart_template_loop_product_thumbnail' ) ) {
  293.     function woodmart_template_loop_product_thumbnail() {
  294.         echo woodmart_get_product_thumbnail();
  295.     }
  296. }
  297.  
  298. if ( ! function_exists( 'woodmart_get_product_thumbnail' ) ) {
  299.     function woodmart_get_product_thumbnail( $size = 'woocommerce_thumbnail', $attach_id = false ) {
  300.         global $post;
  301.         $custom_size = $size;
  302.  
  303.         $defined_sizes = array('woocommerce_thumbnail', 'woodmart_shop_catalog_x2');
  304.        
  305.         if( woodmart_loop_prop( 'double_size' ) ) {
  306.             $size = 'woodmart_shop_catalog_x2';
  307.         }
  308.  
  309.         if ( has_post_thumbnail() ) {
  310.  
  311.             if( ! $attach_id ) $attach_id = get_post_thumbnail_id();
  312.  
  313.             $props = wc_get_product_attachment_props( $attach_id, $post );
  314.            
  315.             if( woodmart_loop_prop( 'img_size' ) ) {
  316.                 $custom_size = woodmart_loop_prop( 'img_size' );
  317.             }
  318.            
  319.             $custom_size = apply_filters( 'woodmart_custom_img_size', $custom_size );
  320.            
  321.             if( ! in_array( $custom_size, $defined_sizes ) && function_exists( 'wpb_getImageBySize' ) ) {
  322.                 $img = wpb_getImageBySize( array( 'attach_id' => $attach_id, 'thumb_size' => $custom_size, 'class' => 'content-product-image' ) );
  323.                 $img = $img['thumbnail'];
  324.  
  325.             } else {
  326.                 $img = wp_get_attachment_image( $attach_id, $size, array(
  327.                     'title'  => $props['title'],
  328.                     'alt'    => $props['alt'],
  329.                 ) );
  330.             }
  331.  
  332.             return $img;
  333.  
  334.         } elseif ( wc_placeholder_img_src() ) {
  335.             return wc_placeholder_img( $size );
  336.         }
  337.     }
  338. }
  339.  
  340. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
  341. add_action( 'woocommerce_before_shop_loop_item_title', 'woodmart_template_loop_product_thumbnail', 10 );
  342.  
  343. if( ! function_exists( 'woodmart_grid_swatches_attribute' ) ) {
  344.     function woodmart_grid_swatches_attribute() {
  345.         $custom = get_post_meta(get_the_ID(),  '_woodmart_swatches_attribute', true );
  346.         return empty( $custom ) ? woodmart_get_opt( 'grid_swatches_attribute' ) : $custom;
  347.     }
  348. }
  349.  
  350. /**
  351.  * ------------------------------------------------------------------------------------------------
  352.  * Get product page classes (columns) for product images and product information blocks
  353.  * ------------------------------------------------------------------------------------------------
  354.  */
  355.  
  356. if( ! function_exists( 'woodmart_product_images_class' ) ) {
  357.     function woodmart_product_images_class() {
  358.         $size = woodmart_product_images_size();
  359.         $layout = woodmart_get_opt( 'single_product_style' );
  360.        
  361.         $class = 'col-lg-' . $size . ' col-12';
  362.  
  363.         $class .= ( $layout == 4 || $layout == 5 ) ? ' col-md-12' : ' col-md-6';
  364.  
  365.         return $class;
  366.     }
  367.  
  368.     function woodmart_product_images_size() {
  369.         $summary_size = ( woodmart_product_summary_size() == 12 ) ? 12 : 12 - woodmart_product_summary_size();
  370.         return apply_filters( 'woodmart_product_summary_size', $summary_size );
  371.     }
  372. }
  373.  
  374. if( ! function_exists( 'woodmart_product_summary_class' ) ) {
  375.     function woodmart_product_summary_class() {
  376.         $size = woodmart_product_summary_size();
  377.         $layout = woodmart_get_opt( 'single_product_style' );
  378.        
  379.         $class = 'col-lg-' . $size . ' col-12';
  380.  
  381.         $class .= ( $layout == 4 || $layout == 5 ) ? ' col-md-12' : ' col-md-6';
  382.  
  383.         if ( woodmart_get_opt( 'single_product_variations_price' ) ) {
  384.             $class .= ' woodmart-price-outside';
  385.         }
  386.  
  387.         return $class;
  388.     }
  389.  
  390.     function woodmart_product_summary_size() {
  391.         $page_layout = woodmart_get_opt( 'single_product_style' );
  392.  
  393.         $size = 6;
  394.         switch ( $page_layout ) {
  395.             case 1:
  396.                 $size = 8;
  397.             break;
  398.             case 2:
  399.                 $size = 6;
  400.             break;
  401.             case 3:
  402.                 $size = 4;
  403.             break;
  404.             case 4:
  405.                 $size = 12;
  406.             break;
  407.             case 5:
  408.                 $size = 12;
  409.             break;
  410.         }
  411.         return apply_filters( 'woodmart_product_summary_size', $size );
  412.     }
  413. }
  414.  
  415. if( ! function_exists( 'woodmart_single_product_class' ) ) {
  416.     function woodmart_single_product_class() {
  417.         $classes = array();
  418.         $classes[] = 'single-product-page';
  419.         $classes[] = 'single-product-content';
  420.  
  421.         $design = woodmart_product_design();
  422.         $product_bg  = woodmart_get_opt( 'product-background' );
  423.         $page_layout = woodmart_get_opt( 'single_product_style' );
  424.        
  425.         $classes[] = 'product-design-' . $design;
  426.         $classes[] = 'tabs-location-' . woodmart_get_opt( 'product_tabs_location' );
  427.         $classes[] = 'tabs-type-' . woodmart_get_opt( 'product_tabs_layout' );
  428.         $classes[] = 'meta-location-' . woodmart_get_opt( 'product_show_meta' );
  429.         $classes[] = 'reviews-location-' . woodmart_get_opt( 'reviews_location' );
  430.  
  431.         if( $design == 'alt' ) {
  432.             $classes[] = 'product-align-center';
  433.         }
  434.  
  435.         if( $page_layout == 4 || $page_layout == 5 ) {
  436.             $classes[] = 'image-full-width';
  437.         }
  438.  
  439.         if( woodmart_get_opt( 'single_full_width' ) ) {
  440.             $classes[] = 'product-full-width';
  441.         }
  442.  
  443.         if( woodmart_get_opt( 'product_summary_shadow' ) ) {
  444.             $classes[] = 'product-summary-shadow';
  445.         }
  446.  
  447.         if( woodmart_product_sticky() ) {
  448.             $classes[] = 'product-sticky-on';
  449.         }
  450.  
  451.         if( ! empty( $product_bg ) &&  ! empty( $product_bg['background-color'] ) ) {
  452.             $classes[] = 'product-has-bg';
  453.         } else {
  454.             $classes[] = 'product-no-bg';
  455.         }
  456.  
  457.         return $classes;
  458.  
  459.     }
  460. }
  461.  
  462. /**
  463.  * ------------------------------------------------------------------------------------------------
  464.  * Configure product image gallery JS
  465.  * ------------------------------------------------------------------------------------------------
  466.  */
  467.  
  468. if( ! function_exists( 'woodmart_get_product_gallery_settings' ) ) {
  469.     function woodmart_get_product_gallery_settings() {
  470.         return apply_filters( 'woodmart_product_gallery_settings', array(
  471.             'images_slider' => woodmart_is_main_product_images_carousel(),
  472.             'thumbs_slider' => array(
  473.                 'enabled' => woodmart_is_product_thumb_enabled(),
  474.                 'position' => woodmart_get_opt('thums_position'),
  475.                 'items' => array(
  476.                     'desktop' => 4,
  477.                     'tablet_landscape' => 3,
  478.                     'tablet' => 4,
  479.                     'mobile' => 3,
  480.                     'vertical_items' => 3
  481.                 )
  482.             )
  483.         ) );
  484.     }
  485. }
  486.  
  487. /**
  488.  * ------------------------------------------------------------------------------------------------
  489.  * Remove product content link
  490.  * ------------------------------------------------------------------------------------------------
  491.  */
  492. remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
  493. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
  494.  
  495. remove_action( 'woocommerce_before_subcategory', 'woocommerce_template_loop_category_link_open', 10 );
  496. remove_action( 'woocommerce_after_subcategory', 'woocommerce_template_loop_category_link_close', 10 );
  497.  
  498. /**
  499.  * ------------------------------------------------------------------------------------------------
  500.  * WooCommerce enqueues 3 stylesheets by default. You can disable them all with the following snippet
  501.  * ------------------------------------------------------------------------------------------------
  502.  */
  503.  
  504. add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
  505.  
  506. /**
  507.  * ------------------------------------------------------------------------------------------------
  508.  * Disable photoswipe
  509.  * ------------------------------------------------------------------------------------------------
  510.  */
  511.  
  512. remove_action( 'wp_footer', 'woocommerce_photoswipe' );
  513.  
  514. /**
  515.  * ------------------------------------------------------------------------------------------------
  516.  * Remove ordering from toolbar
  517.  * ------------------------------------------------------------------------------------------------
  518.  */
  519.  
  520. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
  521.  
  522. /**
  523.  * ------------------------------------------------------------------------------------------------
  524.  * Unhook the WooCommerce wrappers
  525.  * ------------------------------------------------------------------------------------------------
  526.  */
  527.  
  528. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
  529. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
  530.  
  531. /**
  532.  * ------------------------------------------------------------------------------------------------
  533.  * Disable default product zoom init
  534.  * ------------------------------------------------------------------------------------------------
  535.  */
  536. add_filter( 'woocommerce_single_product_zoom_enabled', '__return_false' );
  537.  
  538. /**
  539.  * ------------------------------------------------------------------------------------------------
  540.  * Get CSS class for widget in shop area. Based on the number of widgets
  541.  * ------------------------------------------------------------------------------------------------
  542.  */
  543.  
  544. if( ! function_exists( 'woodmart_get_widget_column_class' ) ) {
  545.     function woodmart_get_widget_column_class( $sidebar_id = 'filters-area' ) {
  546.         global $_wp_sidebars_widgets;
  547.         if ( empty( $_wp_sidebars_widgets ) ) :
  548.             $_wp_sidebars_widgets = get_option( 'sidebars_widgets', array() );
  549.         endif;
  550.        
  551.         $sidebars_widgets_count = $_wp_sidebars_widgets;
  552.  
  553.         if ( isset( $sidebars_widgets_count[ $sidebar_id ] ) || $sidebar_id == 'filters-area' ) {
  554.             $count = ( isset( $sidebars_widgets_count[ $sidebar_id ] ) ) ? count( $sidebars_widgets_count[ $sidebar_id ] ) : 0;
  555.             $widget_count = apply_filters( 'widgets_count_' . $sidebar_id, $count );
  556.             $widget_classes = 'widget-count-' . $widget_count;
  557.             $column = 4;
  558.             if ( $widget_count < 4 && $widget_count != 0 ) {
  559.                 $column = $widget_count;
  560.             }
  561.             $widget_classes .= woodmart_get_grid_el_class( 0, $column, false, 12, 6, 6 );
  562.             return apply_filters( 'widget_class_' . $sidebar_id, $widget_classes);
  563.         }
  564.     }
  565. }
  566.  
  567. /**
  568.  * ------------------------------------------------------------------------------------------------
  569.  * Play with woocommerce hooks
  570.  * ------------------------------------------------------------------------------------------------
  571.  */
  572.  
  573. if( ! function_exists( 'woodmart_woocommerce_hooks' ) ) {
  574.     function woodmart_woocommerce_hooks() {
  575.         global $woodmart_prefix;
  576.  
  577.         $product_meta_position = woodmart_get_opt( 'product_show_meta' );
  578.         $product_show_meta = ( $product_meta_position != 'hide' );
  579.         $product_show_share = woodmart_get_opt( 'product_share' );
  580.         $product_show_desc = woodmart_get_opt( 'product_short_description' );
  581.         $tabs_location = woodmart_get_opt( 'product_tabs_location' );
  582.         $reviews_location = woodmart_get_opt( 'reviews_location' );
  583.  
  584.         remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
  585.         remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  586.  
  587.         // Reviews location
  588.         if( $reviews_location == 'separate' ) {
  589.             add_filter( 'woocommerce_product_tabs', 'woodmart_disable_reviews_tab', 98 );
  590.             add_action( 'woocommerce_after_single_product_summary', 'comments_template', 50 );
  591.         }
  592.  
  593.         // Upsells position
  594.         if( is_singular( 'product' ) ) {
  595.             if( woodmart_get_opt( 'upsells_position' )  == 'sidebar' ) {
  596.                 add_action( 'woodmart_before_sidebar_area', 'woocommerce_upsell_display', 20 );
  597.             } else {
  598.                 add_action( 'woodmart_woocommerce_after_sidebar', 'woocommerce_upsell_display', 10 );
  599.             }
  600.         }
  601.  
  602.         // Disable related products option
  603.         if( woodmart_get_opt('related_products') && ! get_post_meta(get_the_ID(),  '_woodmart_related_off', true ) ) {
  604.             add_action( 'woodmart_woocommerce_after_sidebar', 'woocommerce_output_related_products', 20 );
  605.         }
  606.  
  607.         // Disable product tabs title option
  608.         if( woodmart_get_opt('hide_tabs_titles') || get_post_meta(get_the_ID(),  '_woodmart_hide_tabs_titles', true ) ) {
  609.             add_filter( 'woocommerce_product_description_heading', '__return_false', 20 );
  610.             add_filter( 'woocommerce_product_additional_information_heading', '__return_false', 20 );
  611.         }
  612.  
  613.         if( woodmart_get_opt('shop_filters') ) {
  614.            
  615.             // Use our own order widget list?
  616.             if( apply_filters( 'woodmart_use_custom_order_widget', true ) ) {
  617.                 if( ! is_active_widget( false, false, 'woodmart-woocommerce-sort-by', true ) ) {
  618.                     add_action( 'woodmart_before_filters_widgets', 'woodmart_sorting_widget', 10 );
  619.                 }
  620.                 if ( woodmart_get_opt( 'shop_filters_type' ) == 'widgets' ) {
  621.                     remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
  622.                 }
  623.             }
  624.  
  625.             // Use our custom price filter widget list?
  626.             if( apply_filters( 'woodmart_use_custom_price_widget', true )  && ! is_active_widget( false, false, 'woodmart-price-filter', true ) ) {
  627.                 add_action( 'woodmart_before_filters_widgets', 'woodmart_price_widget', 20 );
  628.             }
  629.  
  630.             // Add 'filters button'
  631.             add_action( 'woocommerce_before_shop_loop', 'woodmart_filter_buttons', 40 );
  632.         }
  633.  
  634.         add_action( 'woocommerce_cart_is_empty', 'woodmart_empty_cart_text', 20 );
  635.  
  636.         /**
  637.          * Remove default empty cart text
  638.          */
  639.         remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
  640.  
  641.         // Wrapp cart totals
  642.  
  643.         add_action( 'woocommerce_before_cart_totals', function() {
  644.             echo '<div class="cart-totals-inner">';
  645.         }, 1);
  646.         add_action( 'woocommerce_after_cart_totals', function() {
  647.             echo '</div><!--.cart-totals-inner-->';
  648.         }, 200);
  649.  
  650.         // Brand tab for single product
  651.         if( woodmart_get_opt( 'brand_tab' ) ) {
  652.             add_filter( 'woocommerce_product_tabs', 'woodmart_product_brand_tab' );
  653.         }
  654.  
  655.         // Poduct brand
  656.         if( woodmart_get_opt( 'product_brand_location' ) == 'about_title' && is_singular( 'product' ) ) {
  657.             add_action( 'woocommerce_single_product_summary', 'woodmart_product_brand', 3);
  658.         } elseif( is_singular( 'product' )) {
  659.             add_action( 'woodmart_before_sidebar_area', 'woodmart_product_brand', 10 );
  660.         }
  661.  
  662.         // Product share
  663.  
  664.         if ( $product_meta_position != 'after_tabs' && $product_show_share ) {
  665.             add_action( 'woocommerce_single_product_summary', 'woodmart_product_share_buttons', 60 );
  666.         }
  667.  
  668.         // Disable meta and description if turned off
  669.         if ( $product_meta_position != 'add_to_cart' ) {
  670.             remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
  671.         }
  672.  
  673.         if ( ! $product_show_desc ) {
  674.             remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
  675.         }
  676.  
  677.         // Product tabs location
  678.  
  679.         if( $tabs_location == 'summary' ) {
  680.             remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
  681.             add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 39 );
  682.         }
  683.  
  684.  
  685.         if ( $product_meta_position == 'after_tabs' ) {
  686.             add_action( 'woodmart_after_product_tabs', function() {
  687.                 echo '<div class="woodmart-before-product-tabs"><div class="container">';
  688.             }, 10 );
  689.  
  690.             remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
  691.             if( $product_show_meta ) add_action( 'woodmart_after_product_tabs', 'woocommerce_template_single_meta', 20 );
  692.             if( $product_show_share ) add_action( 'woodmart_after_product_tabs', 'woodmart_product_share_buttons', 30 );
  693.  
  694.             add_action( 'woodmart_after_product_tabs', function() {
  695.                 echo '</div></div>';
  696.             }, 200 );
  697.         }
  698.  
  699.         // Product video, 360 view, zoom
  700.         $video_url = get_post_meta(get_the_ID(),  '_woodmart_product_video', true );
  701.         $images_360_gallery = woodmart_get_360_gallery_attachment_ids();
  702.         $image_action = woodmart_get_opt( 'image_action' );
  703.  
  704.         if( ! empty( $video_url ) || ! empty( $images_360_gallery ) || ! empty( $image_action ) ) {
  705.             add_action( 'woodmart_on_product_image', 'woodmart_additional_galleries_open', 25 );
  706.             add_action( 'woodmart_on_product_image', 'woodmart_additional_galleries_close', 100 );
  707.         }
  708.        
  709.         if( ! empty( $video_url ) ) {
  710.             add_action( 'woodmart_on_product_image', 'woodmart_product_video_button', 30 );
  711.         }
  712.  
  713.         if( ! empty( $images_360_gallery ) ) {
  714.             add_action( 'woodmart_on_product_image', 'woodmart_product_360_view', 40 );
  715.         }
  716.  
  717.         if( $image_action != 'popup' && woodmart_get_opt( 'photoswipe_icon' ) ) {
  718.             add_action( 'woodmart_on_product_image', 'woodmart_product_zoom_button', 50 );
  719.         }
  720.  
  721.         // Custom extra content
  722.         $extra_block = get_post_meta(get_the_ID(),  '_woodmart_extra_content', true );
  723.  
  724.         if( ! empty( $extra_block ) && $extra_block != 0 ) {
  725.             $extra_position = get_post_meta(get_the_ID(),  '_woodmart_extra_position', true );
  726.             if( $extra_position == 'before' ) {
  727.                 add_action( 'woocommerce_before_single_product', 'woodmart_product_extra_content', 20 );
  728.             } else if( $extra_position == 'prefooter' ) {
  729.                 add_action( 'woodmart_woocommerce_after_sidebar', 'woodmart_product_extra_content', 30 );
  730.             } else {
  731.                 add_action( 'woodmart_after_product_content', 'woodmart_product_extra_content', 20 );
  732.                
  733.             }
  734.         }
  735.  
  736.  
  737.         // Custom tabs
  738.         add_filter( 'woocommerce_product_tabs', 'woodmart_custom_product_tabs' );
  739.  
  740.         // Timer on the single product page
  741.         add_action( 'woocommerce_single_product_summary', 'woodmart_single_product_countdown', 15 );
  742.  
  743.         // Instagram by hashbat for product
  744.         add_action( 'woodmart_woocommerce_after_sidebar', 'woodmart_product_instagram', 80 );
  745.  
  746.         // Cart page move totals
  747.         remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10 );
  748.  
  749.         //Product attibutes after of short description
  750.         if ( woodmart_get_opt( 'attr_after_short_desc' ) ) {
  751.             add_action( 'woocommerce_single_product_summary', 'woodmart_display_product_attributes', 21 );
  752.             add_filter( 'woocommerce_product_tabs', 'woodmart_remove_additional_information_tab', 98 );
  753.         }
  754.  
  755.         //Single product stock progress bar
  756.         if ( woodmart_get_opt( 'single_stock_progress_bar' ) ) {
  757.             add_action( 'woocommerce_single_product_summary', 'woodmart_stock_progress_bar', 16 );
  758.         }
  759.     }
  760.  
  761.     add_action( 'wp', 'woodmart_woocommerce_hooks', 1000 );
  762. }
  763.  
  764.  
  765. if( ! function_exists( 'woodmart_single_product_countdown' ) ) {
  766.     function woodmart_single_product_countdown( $tabs ) {
  767.         $timer = woodmart_get_opt( 'product_countdown' );
  768.         if( $timer ) woodmart_product_sale_countdown();
  769.     }
  770. }
  771.  
  772. if( ! function_exists( 'woodmart_display_product_attributes' ) ) {
  773.     function woodmart_display_product_attributes() {
  774.         global $product;
  775.         if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
  776.             wc_display_product_attributes( $product );
  777.         }
  778.     }
  779. }
  780.  
  781. if( ! function_exists( 'woodmart_remove_additional_information_tab' ) ) {
  782.     function woodmart_remove_additional_information_tab( $tabs ) {
  783.         unset( $tabs['additional_information'] );
  784.         return $tabs;
  785.     }
  786. }
  787.  
  788. /**
  789.  * ------------------------------------------------------------------------------------------------
  790.  * Additional tab
  791.  * ------------------------------------------------------------------------------------------------
  792.  */
  793.  
  794. if( ! function_exists( 'woodmart_custom_product_tabs' ) ) {
  795.     function woodmart_custom_product_tabs( $tabs ) {
  796.         $additional_tab_title = woodmart_get_opt( 'additional_tab_title' );
  797.         $custom_tab_title = get_post_meta( get_the_ID(),  '_woodmart_product_custom_tab_title', true );
  798.        
  799.         if ( $additional_tab_title ) {
  800.             $tabs['woodmart_additional_tab'] = array(
  801.                 'title'     => $additional_tab_title,
  802.                 'priority'  => 50,
  803.                 'callback'  => 'woodmart_additional_product_tab_content'
  804.             );
  805.         }
  806.        
  807.         if ( $custom_tab_title ) {
  808.             $tabs['woodmart_custom_tab'] = array(
  809.                 'title'     => $custom_tab_title,
  810.                 'priority'  => 60,
  811.                 'callback'  => 'woodmart_custom_product_tab_content'
  812.             );
  813.         }
  814.        
  815.         return $tabs;
  816.     }
  817. }
  818.  
  819. if( ! function_exists( 'woodmart_additional_product_tab_content' ) ) {
  820.     function woodmart_additional_product_tab_content() {
  821.         // The new tab content
  822.         $tab_content = woodmart_get_opt( 'additional_tab_text' );
  823.         echo do_shortcode( $tab_content );
  824.        
  825.     }
  826. }
  827.  
  828. if( ! function_exists( 'woodmart_custom_product_tab_content' ) ) {
  829.     function woodmart_custom_product_tab_content() {
  830.         // The new tab content
  831.         $tab_content = get_post_meta( get_the_ID(),  '_woodmart_product_custom_tab_content', true );
  832.         echo do_shortcode( $tab_content );
  833.     }
  834. }
  835.  
  836.  
  837. if( ! function_exists( 'woodmart_disable_reviews_tab' ) ) {
  838.     function woodmart_disable_reviews_tab( $tabs ) {
  839.         unset( $tabs['reviews'] );  // Removes the reviews tab
  840.         return $tabs;
  841.     }
  842. }
  843.  
  844. /**
  845.  * ------------------------------------------------------------------------------------------------
  846.  * Filters buttons
  847.  * ------------------------------------------------------------------------------------------------
  848.  */
  849.  
  850. if( ! function_exists( 'woodmart_filter_widgts_classes' ) ) {
  851.     function woodmart_filter_widgts_classes( $count ) {
  852.  
  853.         if( apply_filters( 'woodmart_use_custom_order_widget', true )  && ! is_active_widget( false, false, 'woodmart-woocommerce-sort-by', true ) ) {
  854.             $count++;
  855.         }
  856.  
  857.         if( apply_filters( 'woodmart_use_custom_price_widget', true )  && ! is_active_widget( false, false, 'woodmart-price-filter', true ) ) {
  858.             $count++;
  859.         }
  860.  
  861.         return $count;
  862.     }
  863.  
  864.     add_filter('widgets_count_filters-area', 'woodmart_filter_widgts_classes');
  865. }
  866.  
  867. /**
  868.  * ------------------------------------------------------------------------------------------------
  869.  * Force WOODMART Swatche layered nav and price widget to work
  870.  * ------------------------------------------------------------------------------------------------
  871.  */
  872.  
  873.  
  874. add_filter( 'woocommerce_is_layered_nav_active', 'woodmart_is_layered_nav_active' );
  875. if( ! function_exists( 'woodmart_is_layered_nav_active' ) ) {
  876.     function woodmart_is_layered_nav_active() {
  877.         return is_active_widget( false, false, 'woodmart-woocommerce-layered-nav', true );
  878.     }
  879. }
  880.  
  881. add_filter( 'woocommerce_is_price_filter_active', 'woodmart_is_layered_price_active' );
  882.  
  883. if( ! function_exists( 'woodmart_is_layered_price_active' ) ) {
  884.     function woodmart_is_layered_price_active() {
  885.         $result = is_active_widget( false, false, 'woodmart-price-filter', true );
  886.         if( ! $result ) {
  887.             $result = apply_filters( 'woodmart_use_custom_price_widget', true );
  888.         }
  889.         return $result;
  890.     }
  891. }
  892.  
  893.  
  894.  
  895. /**
  896.  * ------------------------------------------------------------------------------------------------
  897.  * Change the position of woocommerce breadcrumbs
  898.  * ------------------------------------------------------------------------------------------------
  899.  */
  900. remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
  901.  
  902. /**
  903.  * ------------------------------------------------------------------------------------------------
  904.  * Add photoswipe template to body
  905.  * ------------------------------------------------------------------------------------------------
  906.  */
  907. add_action( 'woodmart_after_footer', 'woodmart_photoswipe_template', 1000 );
  908. if( ! function_exists( 'woodmart_photoswipe_template' ) ) {
  909.     function woodmart_photoswipe_template() {
  910.         get_template_part('woocommerce/single-product/photo-swipe-template');
  911.     }
  912. }
  913.  
  914.  
  915. // **********************************************************************//
  916. // ! Start woocommerce customer session
  917. // **********************************************************************//
  918.  
  919. if( ! function_exists( 'woodmart_set_customer_session' ) ) {
  920.  
  921.     add_action( 'woodmart_before_shop_page', 'woodmart_set_customer_session', 10 );
  922.  
  923.     function woodmart_set_customer_session() {
  924.         if( ! function_exists( 'WC' ) ) return;
  925.         if ( WC()->version > '2.1' && ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) ) :
  926.             WC()->session->set_customer_session_cookie( true );
  927.         endif;
  928.     }
  929. }
  930.  
  931. // **********************************************************************//
  932. // ! Items per page select on the shop page
  933. // **********************************************************************//
  934.  
  935.  
  936. if( ! function_exists( 'woodmart_products_per_page_action' ) ) {
  937.  
  938.     add_action( 'woodmart_before_shop_page', 'woodmart_products_per_page_action', 100 );
  939.  
  940.     function woodmart_products_per_page_action() {
  941.         if ( isset( $_REQUEST['per_page'] ) ) :
  942.             if( ! class_exists('WC_Session_Handler')) return;
  943.             $s = WC()->session; // WC()->session
  944.             if ( is_null( $s ) ) return;
  945.            
  946.             $s->set( 'shop_per_page', intval( $_REQUEST['per_page'] ) );
  947.         endif;
  948.     }
  949. }
  950.  
  951. // **********************************************************************//
  952. // ! Get Items per page number on the shop page
  953. // **********************************************************************//
  954.  
  955. if( ! function_exists( 'woodmart_get_products_per_page' ) ) {
  956.     function woodmart_get_products_per_page() {
  957.         if( ! class_exists('WC_Session_Handler') ) return;
  958.         $s = WC()->session; // WC()->session
  959.         if ( is_null( $s ) ) return intval( woodmart_get_opt('shop_per_page') );
  960.        
  961.         if ( isset( $_REQUEST['per_page'] ) && ! empty( $_REQUEST['per_page'] ) ) :
  962.             return intval( $_REQUEST['per_page'] );
  963.         elseif ( $s->__isset( 'shop_per_page' ) ) :
  964.             $val = $s->__get( 'shop_per_page' );
  965.             if( ! empty( $val ) )
  966.                 return intval( $s->__get( 'shop_per_page' ) );
  967.         endif;
  968.         return intval( woodmart_get_opt('shop_per_page') );
  969.     }
  970. }
  971.  
  972.  
  973. // **********************************************************************//
  974. // ! Items view select on the shop page
  975. // **********************************************************************//
  976.  
  977. if( ! function_exists( 'woodmart_shop_view_action' ) ) {
  978.  
  979.     add_action( 'woodmart_before_shop_page', 'woodmart_shop_view_action', 100 );
  980.  
  981.     function woodmart_shop_view_action() {
  982.         if( ! class_exists('WC_Session_Handler')) return;
  983.         $s = WC()->session; // WC()->session
  984.         if ( is_null( $s ) ) return;
  985.  
  986.         if ( isset( $_REQUEST['shop_view'] ) ) {
  987.             $s->set( 'shop_view', $_REQUEST['shop_view'] );
  988.         }
  989.         if ( isset( $_REQUEST['per_row'] ) ) {
  990.             $s->set( 'shop_per_row', $_REQUEST['per_row'] );
  991.         }
  992.     }
  993. }
  994. // **********************************************************************//
  995. // ! Get Items per ROW number on the shop page
  996. // **********************************************************************//
  997.  
  998. if( ! function_exists( 'woodmart_get_products_columns_per_row' ) ) {
  999.     function woodmart_get_products_columns_per_row() {
  1000.         if( ! class_exists('WC_Session_Handler') ) return;
  1001.         $s = WC()->session; // WC()->session
  1002.         if ( is_null( $s ) ) return intval( woodmart_get_opt('products_columns') );
  1003.  
  1004.         if ( isset( $_REQUEST['per_row'] ) ) {
  1005.             return intval( $_REQUEST['per_row'] );
  1006.         }elseif ( $s->__isset( 'shop_per_row' ) ) {
  1007.             return intval( $s->__get( 'shop_per_row' ) );
  1008.         }else {
  1009.             return intval( woodmart_get_opt('products_columns') );
  1010.         }
  1011.     }
  1012. }
  1013.  
  1014. if( ! function_exists( 'woodmart_get_shop_view' ) ) {
  1015.     function woodmart_get_shop_view() {
  1016.         if( ! class_exists('WC_Session_Handler') ) return;
  1017.         $s = WC()->session; // WC()->session
  1018.         if ( is_null( $s ) ) return woodmart_get_opt('shop_view');
  1019.  
  1020.         if ( isset( $_REQUEST['shop_view'] ) ) {
  1021.             return $_REQUEST['shop_view'];
  1022.         }elseif ( $s->__isset( 'shop_view' ) ) {
  1023.             return $s->__get( 'shop_view' );
  1024.         }else {
  1025.             $shop_view = woodmart_get_opt('shop_view');
  1026.             if ( $shop_view == 'grid_list' ) {
  1027.                 return 'grid';
  1028.             }elseif( $shop_view == 'list_grid'){
  1029.                 return 'list';
  1030.             }else{
  1031.                 return $shop_view;
  1032.             }
  1033.         }
  1034.     }
  1035. }
  1036.  
  1037. /**
  1038.  * ------------------------------------------------------------------------------------------------
  1039.  * Remove () from numbers in categories widget
  1040.  * ------------------------------------------------------------------------------------------------
  1041.  */
  1042.  
  1043. if( ! function_exists( 'woodmart_filter_product_categories_widget_args' ) ) {
  1044.     function woodmart_filter_product_categories_widget_args( $list_args ) {
  1045.  
  1046.         $list_args['walker'] = new WOODMART_WC_Product_Cat_List_Walker();
  1047.  
  1048.         return $list_args;
  1049.     }
  1050.  
  1051.     add_filter( 'woocommerce_product_categories_widget_args', 'woodmart_filter_product_categories_widget_args', 10, 1);
  1052. }
  1053.  
  1054. /**
  1055.  * ------------------------------------------------------------------------------------------------
  1056.  * AJAX add to cart for all product types
  1057.  * ------------------------------------------------------------------------------------------------
  1058.  */
  1059.  
  1060. if( ! function_exists( 'woodmart_ajax_add_to_cart' ) ) {
  1061.     function woodmart_ajax_add_to_cart() {
  1062.         // Get messages
  1063.         ob_start();
  1064.  
  1065.         wc_print_notices();
  1066.  
  1067.         $notices = ob_get_clean();
  1068.  
  1069.  
  1070.         // Get mini cart
  1071.         ob_start();
  1072.  
  1073.         woocommerce_mini_cart();
  1074.  
  1075.         $mini_cart = ob_get_clean();
  1076.  
  1077.         // Fragments and mini cart are returned
  1078.         $data = array(
  1079.             'notices' => $notices,
  1080.             'fragments' => apply_filters( 'woocommerce_add_to_cart_fragments', array(
  1081.                     'div.widget_shopping_cart_content' => '<div class="widget_shopping_cart_content">' . $mini_cart . '</div>'
  1082.                 )
  1083.             ),
  1084.             'cart_hash' => apply_filters( 'woocommerce_add_to_cart_hash', WC()->cart->get_cart_for_session() ? md5( json_encode( WC()->cart->get_cart_for_session() ) ) : '', WC()->cart->get_cart_for_session() )
  1085.         );
  1086.  
  1087.         wp_send_json( $data );
  1088.  
  1089.         die();
  1090.     }
  1091. }
  1092.  
  1093. add_action( 'wp_ajax_woodmart_ajax_add_to_cart', 'woodmart_ajax_add_to_cart' );
  1094. add_action( 'wp_ajax_nopriv_woodmart_ajax_add_to_cart', 'woodmart_ajax_add_to_cart' );
  1095.  
  1096. /**
  1097.  * ------------------------------------------------------------------------------------------------
  1098.  * Function to prepare classes for grid element (column)
  1099.  * ------------------------------------------------------------------------------------------------
  1100.  */
  1101.  
  1102. if ( ! function_exists( 'woodmart_get_grid_el_class' ) ) {
  1103.     function woodmart_get_grid_el_class( $loop = 0, $columns = 4, $different_sizes = false, $xs_size = false, $sm_size = 4, $lg_size = 3, $md_size = false ) {
  1104.         $classes = '';
  1105.  
  1106.         $items_wide = woodmart_get_wide_items_array( $different_sizes );
  1107.  
  1108.         if ( ! $xs_size ) {
  1109.             $xs_size = apply_filters( 'woodmart_grid_xs_default', 6 );
  1110.         }
  1111.  
  1112.         if ( $columns > 0 ) {
  1113.             $lg_size = 12 / $columns;
  1114.         }
  1115.  
  1116.         if ( ! $md_size ) {
  1117.             $md_size = $lg_size;
  1118.         }
  1119.  
  1120.         if ( $columns > 4 ) {
  1121.             $md_size = 3;
  1122.         }
  1123.  
  1124.         if ( $columns <= 3 ) {
  1125.             if ( $columns == 1 ) {
  1126.                 $sm_size = 12;
  1127.                 $xs_size = 12;
  1128.             } else {
  1129.                 $sm_size = 6;
  1130.             }
  1131.         }
  1132.  
  1133.         // Change the layout alternating columns
  1134.         if ( $different_sizes && ( in_array( $loop, $items_wide ) )) {
  1135.            
  1136.             switch ($columns):
  1137.                
  1138.                 case 3:
  1139.                     $lg_size = 6;
  1140.                     $md_size = 6;
  1141.                 break;
  1142.                
  1143.                 case 4:
  1144.                     $lg_size = 4;
  1145.                     $md_size = 4;
  1146.                 break;
  1147.                
  1148.                 case 5:
  1149.                     $lg_size = 3;
  1150.                     $md_size = 3;
  1151.                 break;
  1152.                
  1153.                 case 6:
  1154.                     $lg_size = '20_0';
  1155.                     $md_size = 3;
  1156.                 break;
  1157.            
  1158.             endswitch;
  1159.    
  1160.         }
  1161.        
  1162.         /*
  1163.         Because you made a custom work for showing 5 columns layout i rewrote the code so that
  1164.         when the Products grid with different sizes is disabled the columns work as normal
  1165.         but when is enabled to make the 5-4-5 layout work
  1166.         */
  1167.        
  1168.         if ( ! $different_sizes && ( in_array( $columns, array( 5, 7, 8, 9, 10, 11 ) ) )) {
  1169.             $lg_size = str_replace( '.', '_', round( 100 / $columns, 1 ) );
  1170.             if ( ! strpos( $lg_size, '_' ) ) {
  1171.                 $lg_size = $lg_size . '_0';
  1172.             }
  1173.         }
  1174.         if ( ! in_array( $loop, $items_wide ) &&  ( in_array( $columns, array( 5, 7, 8, 9, 10, 11 ) ) ) ) {
  1175.             $lg_size = str_replace( '.', '_', round( 100 / $columns, 1 ) );
  1176.             if ( ! strpos( $lg_size, '_' ) ) {
  1177.                 $lg_size = $lg_size . '_0';
  1178.             }
  1179.         }
  1180.        
  1181.         $sizes = array(
  1182.             array(
  1183.                 'name' => 'col-lg',
  1184.                 'value' => $lg_size,
  1185.             ),
  1186.             array(
  1187.                 'name' => 'col-md',
  1188.                 'value' => $md_size,
  1189.             ),
  1190.             array(
  1191.                 'name' => 'col-sm',
  1192.                 'value' => $sm_size,
  1193.             ),
  1194.             array(
  1195.                 'name' => 'col',
  1196.                 'value' => $xs_size,
  1197.             ),
  1198.         );
  1199.        
  1200.         $result_sizes = array();
  1201.         foreach ( $sizes as $index => $value ) {
  1202.             if ( isset( $sizes[$index + 1] ) ) {
  1203.                 $next = $sizes[$index + 1];
  1204.             } else {
  1205.                 continue;
  1206.             }
  1207.            
  1208.             if ( $value['value'] === $next['value'] ) {
  1209.                 $result_sizes[$next['name']] = $next['value'];
  1210.                 unset($result_sizes[$value['name']]);
  1211.             } else if ( $value['value'] !== $next['value'] ) {
  1212.                 $result_sizes[$value['name']] = $value['value'];
  1213.                 $result_sizes[$next['name']] = $next['value'];
  1214.             }
  1215.         }
  1216.        
  1217.         if ( apply_filters( 'woodmart_old_product_grid_classes', false ) ) {
  1218.             $result_sizes = array(
  1219.                 'col-lg' => $lg_size,
  1220.                 'col-md' => $md_size,
  1221.                 'col-sm' => $sm_size,
  1222.                 'col' => $xs_size,
  1223.             );
  1224.         }
  1225.  
  1226.         foreach ( $result_sizes as $size => $value ) {
  1227.             $classes .= ' ' . $size . '-' . $value;
  1228.         }
  1229.        
  1230.         if ( $loop > 0 && $columns > 0 ) {
  1231.             if ( 0 == ( $loop - 1 ) % $columns || 1 == $columns ) {
  1232.                 $classes .= ' first ';
  1233.             }
  1234.             if ( 0 == $loop % $columns ) {
  1235.                 $classes .= ' last ';
  1236.             }
  1237.         }
  1238.  
  1239.         return $classes;
  1240.     }
  1241. }
  1242.  
  1243.  
  1244. if ( ! function_exists( 'woodmart_get_wide_items_array' ) ) {
  1245.     function woodmart_get_wide_items_array( $different_sizes = false ){
  1246.        
  1247.         //To create an array big enough so that the alternate pattern repeats and not stops after few products
  1248.         $loop_cycle = 999;
  1249.        
  1250.         //Get the selected columns
  1251.         $perrow = apply_filters( 'loop_shop_columns', woodmart_get_products_columns_per_row() );
  1252.        
  1253. /**
  1254.  
  1255. You default function defined an array of ( 5, 6, 7, 8, 13, 14 )
  1256. basically what it does was to change the product size in products
  1257. that were inside this array, after the 14 product the repeated pattern stoped.
  1258.  
  1259. Below i create a function that does the following thing.
  1260. If you choose a 3 column layout it puts in array the numbers 4, 5 then skips 6, 7, 8
  1261. and puts 9, 10 and so on.
  1262.  
  1263. These numbers in array are the positions of the products that have to change the size so that the final result looks like
  1264.  
  1265. 3, 3, 3
  1266.  
  1267. 2, 2 => products position 4, 5
  1268.  
  1269. 3, 3, 3
  1270.  
  1271. 2, 2 => products position 9, 10
  1272.  
  1273. and so on
  1274.  
  1275. Another example is
  1276.  
  1277. 4, 4, 4, 4
  1278.  
  1279. 3, 3, 3 => products position 5, 6, 7
  1280.  
  1281. 4, 4, 4, 4
  1282.  
  1283. 3, 3, 3 => products position 12, 13, 14
  1284.  
  1285.  
  1286. This function works according to what collumn you have selected.
  1287.  
  1288.  
  1289. So if you select a grid layout with 3 columns the pattern will be
  1290.  
  1291. 3/2
  1292.  
  1293. For 4 columns the pattern will be
  1294.  
  1295. 4/3
  1296.  
  1297. for 5
  1298.  
  1299. 5/4
  1300.  
  1301. for 6
  1302.  
  1303. 6/5
  1304.  
  1305.  
  1306.  
  1307.  
  1308. **/
  1309.        
  1310.         //My custom function Starts
  1311.         $stop = ($perrow+($perrow-1))*$loop_cycle;
  1312.         $cycle = $perrow+($perrow-1);
  1313.        
  1314.         $arr = array();
  1315.        
  1316.        
  1317.         for ($i=1; $i<=$stop; $i++) {
  1318.             if ($i>($cycle-($perrow-1)) && $i<=$cycle) {
  1319.                 array_push($arr, $i);
  1320.                 if ($i==$cycle) $cycle += $perrow+($perrow-1);
  1321.             } else continue;
  1322.         }
  1323.        
  1324.         return $arr;
  1325.         //My custom function Ends
  1326.        
  1327.        
  1328.        
  1329.         //Instead of array( 5, 6, 7, 8, 13, 14 ) i put the $arr array that generated above
  1330.         $items_wide = apply_filters( 'woodmart_wide_items', array( $arr ) );
  1331.  
  1332.         if( is_array( $different_sizes ) ) {
  1333.             $items_wide = apply_filters( 'woodmart_wide_items', $different_sizes );
  1334.         }
  1335.  
  1336.         return $items_wide;
  1337.     }
  1338. }
  1339.  
  1340. /**
  1341.  * ------------------------------------------------------------------------------------------------
  1342.  * Woodmart Related product count
  1343.  * ------------------------------------------------------------------------------------------------
  1344.  */
  1345. if( ! function_exists( 'woodmart_related_count' ) ) {
  1346.     add_filter( 'woocommerce_output_related_products_args', 'woodmart_related_count' );
  1347.       function woodmart_related_count() {
  1348.         $args['posts_per_page'] = ( woodmart_get_opt( 'related_product_count' ) ) ? woodmart_get_opt( 'related_product_count' ) : 8;
  1349.         return $args;
  1350.     }
  1351. }
  1352.  
  1353. /**
  1354.  * ------------------------------------------------------------------------------------------------
  1355.  * Reset loop
  1356.  * ------------------------------------------------------------------------------------------------
  1357.  */
  1358.  
  1359. if( ! function_exists( 'woodmart_reset_loop' ) ) {
  1360.     function woodmart_reset_loop() {
  1361.         unset( $GLOBALS['woodmart_loop'] );
  1362.         woodmart_setup_loop();
  1363.     }
  1364.     add_action( 'woocommerce_after_shop_loop', 'woodmart_reset_loop', 1000 );
  1365.     add_action( 'loop_end', 'woodmart_reset_loop', 1000 );
  1366. }
  1367.  
  1368. /**
  1369.  * ------------------------------------------------------------------------------------------------
  1370.  * Get loop prop
  1371.  * ------------------------------------------------------------------------------------------------
  1372.  */
  1373.  
  1374. if( ! function_exists( 'woodmart_loop_prop' ) ) {
  1375.     function woodmart_loop_prop( $prop, $default = '' ) {
  1376.         woodmart_setup_loop();
  1377.        
  1378.         return isset( $GLOBALS['woodmart_loop'], $GLOBALS['woodmart_loop'][ $prop ] ) ? $GLOBALS['woodmart_loop'][ $prop ] : $default;
  1379.     }
  1380. }
  1381.  
  1382. /**
  1383.  * ------------------------------------------------------------------------------------------------
  1384.  * Set loop prop
  1385.  * ------------------------------------------------------------------------------------------------
  1386.  */
  1387.  
  1388. if( ! function_exists( 'woodmart_set_loop_prop' ) ) {
  1389.     function woodmart_set_loop_prop( $prop, $value = '' ) {
  1390.         if ( ! isset( $GLOBALS['woodmart_loop'] ) ) woodmart_setup_loop();
  1391.  
  1392.         $GLOBALS['woodmart_loop'][ $prop ] = $value;
  1393.     }
  1394. }
  1395.  
  1396. /**
  1397.  * ------------------------------------------------------------------------------------------------
  1398.  * Setup loop
  1399.  * ------------------------------------------------------------------------------------------------
  1400.  */
  1401.  
  1402. if( ! function_exists( 'woodmart_setup_loop' ) ) {
  1403.     function woodmart_setup_loop( $args = array() ) {
  1404.         if ( isset( $GLOBALS['woodmart_loop'] ) ) return; // If the loop has already been setup, bail.
  1405.        
  1406.         $default_args = array(
  1407.             'products_different_sizes'  => woodmart_get_opt( 'products_different_sizes' ),
  1408.             'product_categories_design' => woodmart_get_opt( 'categories_design' ),
  1409.             'product_categories_shadow' => woodmart_get_opt( 'categories_with_shadow' ),
  1410.             'products_columns'          => ( woodmart_get_opt( 'per_row_columns_selector' ) ) ? apply_filters( 'loop_shop_columns', woodmart_get_products_columns_per_row() ) : woodmart_get_opt( 'products_columns' ),
  1411.             'product_categories_style'  => false,
  1412.             'product_hover'             => woodmart_get_opt( 'products_hover' ),
  1413.             'products_view'             => woodmart_get_shop_view(),
  1414.             'products_masonry'          => woodmart_get_opt( 'products_masonry' ),
  1415.            
  1416.             'timer'                     => woodmart_get_opt( 'shop_countdown' ),
  1417.             'progress_bar'              => woodmart_get_opt( 'grid_stock_progress_bar' ),
  1418.             'swatches'                  => false,
  1419.            
  1420.             'is_slider'                 => false,
  1421.             'is_shortcode'              => false,
  1422.             'is_quick_view'             => false,
  1423.            
  1424.             'woocommerce_loop'          => 0,
  1425.             'woodmart_loop'             => 0,
  1426.            
  1427.             'parts_media'               => true,
  1428.             'parts_title'               => true,
  1429.             'parts_meta'                => true,
  1430.             'parts_text'                => true,
  1431.             'parts_btn'                 => true,
  1432.            
  1433.             'blog_design'               => woodmart_get_opt( 'blog_design' ),
  1434.             'blog_type'                 => false,
  1435.             'blog_columns'              => woodmart_get_opt( 'blog_columns' ),
  1436.             'img_size'                  => false,
  1437.             'double_size'               => false,
  1438.  
  1439.             'portfolio_style'           => woodmart_get_opt( 'portoflio_style' ),
  1440.             'portfolio_column'          => woodmart_get_opt( 'projects_columns' ),
  1441.         );
  1442.        
  1443.         $GLOBALS['woodmart_loop'] = wp_parse_args( $args, $default_args );
  1444.     }
  1445.     add_action( 'woocommerce_before_shop_loop', 'woodmart_setup_loop', 10 );
  1446.     add_action( 'wp', 'woodmart_setup_loop', 50 );
  1447.     add_action( 'loop_start', 'woodmart_setup_loop', 10 );
  1448. }
  1449.  
  1450. /**
  1451.  * ------------------------------------------------------------------------------------------------
  1452.  * Hide woocommerce notice
  1453.  * ------------------------------------------------------------------------------------------------
  1454.  */
  1455. if ( ! function_exists( 'woodmart_hide_outdated_templates_notice' ) ) {
  1456.     function woodmart_hide_outdated_templates_notice( $value, $notice ) {
  1457.         if ( $notice == 'template_files' ) {
  1458.             return false;
  1459.         }
  1460.  
  1461.         return $value;
  1462.     }
  1463.  
  1464.     add_filter( 'woocommerce_show_admin_notice', 'woodmart_hide_outdated_templates_notice', 2, 10 );
  1465. }
  1466.  
  1467. /**
  1468.  * ------------------------------------------------------------------------------------------------
  1469.  * Fix for single product image sizes
  1470.  * ------------------------------------------------------------------------------------------------
  1471.  */
  1472. if ( ! function_exists( 'woodmart_single_product_image_sizes') ) {
  1473.     function woodmart_single_product_image_sizes() {
  1474.         $sizes = wc_get_image_size( 'woocommerce_single' );
  1475.         if ( ! $sizes['height'] ) {
  1476.             $sizes['height'] = $sizes['width'];
  1477.         }
  1478.  
  1479.         return array( $sizes['width'], $sizes['height'] );
  1480.     }
  1481.  
  1482.     add_filter( 'woocommerce_gallery_thumbnail_size', 'woodmart_single_product_image_sizes' );
  1483. }
  1484.  
  1485.  
  1486. /**
  1487.  * ------------------------------------------------------------------------------------------------
  1488.  * Change single product notice position
  1489.  * ------------------------------------------------------------------------------------------------
  1490.  */
  1491. remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
  1492. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 );
  1493.  
  1494. add_action( 'woodmart_before_single_product_summary_wrap', 'woocommerce_output_all_notices', 10 );
  1495. add_action( 'woodmart_before_shop_page', 'woocommerce_output_all_notices', 10 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement