default.php
173 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The Template for displaying product archives, including the main shop page which is a post type archive |
| 4 | * |
| 5 | * This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php. |
| 6 | * |
| 7 | * HOWEVER, on occasion WooCommerce will need to update template files and you |
| 8 | * (the theme developer) will need to copy the new files to your theme to |
| 9 | * maintain compatibility. We try to do this as little as possible, but it does |
| 10 | * happen. When this occurs the version of the template file will be bumped and |
| 11 | * the readme will list any important changes. |
| 12 | * |
| 13 | * @see https://docs.woocommerce.com/document/template-structure/ |
| 14 | * @package WooCommerce\Templates |
| 15 | * @version 3.4.0 |
| 16 | * |
| 17 | * /woocommerce/templates/archive-product.php |
| 18 | */ |
| 19 | |
| 20 | \ShopEngine\Widgets\Widget_Helper::instance()->wc_template_part_filter_by_match('woocommerce/content-product.php', 'templates/content-product.php'); |
| 21 | \ShopEngine\Widgets\Widget_Helper::instance()->wc_template_filter(); |
| 22 | |
| 23 | $wrap_extra_class = sprintf('%1$s%2$s', |
| 24 | $shopengine_use_layout === 'yes' ? 'shopengine-grid' : '', |
| 25 | ($shopengine_is_hover_details !== 'yes' && $shopengine_group_btns !== 'yes') ? ' shopengine-hover-disable' : '' |
| 26 | ); |
| 27 | ?> |
| 28 | <div data-pagination="<?php echo esc_attr($shopengine_pagination_style) ?>" |
| 29 | class="shopengine-archive-products <?php echo esc_attr($wrap_extra_class); ?>"> |
| 30 | <?php |
| 31 | |
| 32 | // add product description |
| 33 | add_action('woocommerce_after_shop_loop_item_title', function () use ($shopengine_is_details, $shopengine_group_btns, $shopengine_is_hover_details) { |
| 34 | if($shopengine_is_hover_details === 'yes') : ?> |
| 35 | <div class="shopengine-product-description-footer"> |
| 36 | <?php endif; |
| 37 | |
| 38 | if($shopengine_is_details === 'yes') : |
| 39 | ?> |
| 40 | <div class="shopengine-product-excerpt"> <?php |
| 41 | the_excerpt(); |
| 42 | ?> </div> <?php |
| 43 | endif; |
| 44 | |
| 45 | if($shopengine_is_hover_details === 'yes') : ?> |
| 46 | <?php if($shopengine_group_btns !== 'yes') : ?> |
| 47 | <div class="shopengine-product-description-btn-group"> |
| 48 | <?php woocommerce_template_loop_add_to_cart(); ?> |
| 49 | </div> |
| 50 | <?php endif; ?> |
| 51 | </div> <?php |
| 52 | endif; |
| 53 | }, 40); |
| 54 | |
| 55 | $wp_query_args = ['post_type' => 'product']; |
| 56 | /* |
| 57 | --------------------------------------------- |
| 58 | - $query_attributes['columns'] |
| 59 | - $query_attributes['rows'] |
| 60 | Note: these variabels represets the numbers of rows and columns set by the user inside of |
| 61 | archvie product widget. By enabling this options woocommerce customizer controls will not work |
| 62 | --------------------------------------------- |
| 63 | */ |
| 64 | if($shopengine_use_layout === 'yes' && isset($shopengine_columns['size']) && isset($shopengine_rows['size'])) { |
| 65 | |
| 66 | $col = $shopengine_columns['size']; |
| 67 | $post_per_page = $col * $shopengine_rows['size']; |
| 68 | |
| 69 | if($post_per_page >= 8) { |
| 70 | $post_per_page += 1; |
| 71 | } |
| 72 | |
| 73 | add_filter('loop_shop_columns', function () use ($col) { |
| 74 | return $col; // 3 products per row |
| 75 | }, 999); |
| 76 | |
| 77 | $wp_query_args['posts_per_page'] = $post_per_page; |
| 78 | |
| 79 | } // end of widget control section |
| 80 | |
| 81 | // pagination next previous button label filter |
| 82 | |
| 83 | if($shopengine_pagination_style === 'numeric') { |
| 84 | $control_args['prev_icon'] = '<i class="' . esc_attr($shopengine_pagination_prev_icon['value']) . '"></i>'; |
| 85 | $control_args['next_icon'] = '<i class="' . esc_attr($shopengine_pagination_next_icon['value']) . '"></i>'; |
| 86 | } |
| 87 | |
| 88 | if($shopengine_pagination_style === 'default') { |
| 89 | $control_args['prev_icon'] = $shopengine_pagination_prev_text; |
| 90 | $control_args['next_icon'] = $shopengine_pagination_next_text; |
| 91 | } |
| 92 | |
| 93 | if($shopengine_pagination_style === 'load-more' || $shopengine_pagination_style === 'load-more-on-scroll') { |
| 94 | $control_args['prev_icon'] = ''; |
| 95 | $control_args['next_icon'] = $shopengine_pagination_loadmore_text; |
| 96 | } |
| 97 | |
| 98 | if(isset($control_args)) { |
| 99 | add_filter('woocommerce_pagination_args', function ($args) use ($control_args) { |
| 100 | $args['prev_text'] = $control_args['prev_icon']; |
| 101 | $args['next_text'] = $control_args['next_icon']; |
| 102 | |
| 103 | return $args; |
| 104 | }); |
| 105 | } |
| 106 | |
| 107 | $page_type = \ShopEngine\Widgets\Products::instance()->get_template_type_by_id(get_the_ID()); |
| 108 | if(in_array($page_type, ['archive', 'shop', 'search']) && (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_preview())) { |
| 109 | |
| 110 | global $wp_query, $post;; |
| 111 | $main_query = clone $wp_query; |
| 112 | $main_post = clone $post; |
| 113 | $wp_query = new \WP_Query($wp_query_args); |
| 114 | |
| 115 | wc_setup_loop( |
| 116 | [ |
| 117 | 'is_filtered' => is_filtered(), |
| 118 | 'total' => $wp_query->found_posts, |
| 119 | 'total_pages' => $wp_query->max_num_pages, |
| 120 | 'per_page' => $wp_query->get('posts_per_page'), |
| 121 | 'current_page' => max(1, $wp_query->get('paged', 1)), |
| 122 | ] |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | $run_loop = (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_preview() ? true : woocommerce_product_loop()); |
| 127 | |
| 128 | if($run_loop) { |
| 129 | |
| 130 | do_action('woocommerce_before_shop_loop'); |
| 131 | |
| 132 | woocommerce_product_loop_start(); |
| 133 | |
| 134 | if(wc_get_loop_prop('total')) { |
| 135 | while(have_posts()) { |
| 136 | the_post(); |
| 137 | |
| 138 | /** |
| 139 | * Hook: woocommerce_shop_loop. |
| 140 | */ |
| 141 | do_action('woocommerce_shop_loop'); |
| 142 | |
| 143 | wc_get_template_part('content', 'product'); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | woocommerce_product_loop_end(); |
| 148 | |
| 149 | /** |
| 150 | * Hook: woocommerce_after_shop_loop. |
| 151 | * |
| 152 | * @hooked woocommerce_pagination - 10 |
| 153 | */ |
| 154 | do_action('woocommerce_after_shop_loop'); |
| 155 | |
| 156 | } else { |
| 157 | /** |
| 158 | * Hook: woocommerce_no_products_found. |
| 159 | * |
| 160 | * @hooked wc_no_products_found - 10 |
| 161 | */ |
| 162 | do_action('woocommerce_no_products_found'); |
| 163 | } |
| 164 | |
| 165 | if(in_array($page_type, ['archive', 'shop', 'search']) && (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_preview())) { |
| 166 | $wp_query = $main_query; |
| 167 | $post = $main_post; |
| 168 | wp_reset_query(); |
| 169 | wp_reset_postdata(); |
| 170 | } |
| 171 | ?> |
| 172 | </div> |
| 173 |