default.php
320 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This template will overwrite the WooCommerce file: woocommerce/archive-product.php. |
| 4 | */ |
| 5 | defined('ABSPATH') || exit; |
| 6 | \ShopEngine\Widgets\Widget_Helper::instance()->wc_template_part_filter_by_match('woocommerce/content-product.php', 'templates/content-product.php'); |
| 7 | \ShopEngine\Widgets\Widget_Helper::instance()->wc_template_filter(); |
| 8 | \ShopEngine\Compatibility\Conflicts\Theme_Hooks::instance()->theme_conflicts__archive_products_widget_during_render(); |
| 9 | |
| 10 | // Extract settings passed from screen method |
| 11 | extract($settings_to_pass); |
| 12 | $wrap_extra_class = sprintf('%1$s%2$s', 'shopengine-grid', ($shopengine_is_hover_details !== 'yes' && $shopengine_group_btns !== 'yes') ? ' shopengine-hover-disable' : ''); |
| 13 | |
| 14 | $editor_mode = ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_preview() ) ; |
| 15 | |
| 16 | ?> |
| 17 | <?php |
| 18 | if ( is_plugin_active( 'iconic-woo-image-swap/iconic-woo-image-swap.php' ) ) |
| 19 | { |
| 20 | global $iconic_woo_image_swap_class; |
| 21 | remove_action('woocommerce_before_shop_loop_item',array($iconic_woo_image_swap_class,'template_loop_product_thumbnail'),5); |
| 22 | |
| 23 | } |
| 24 | ?> |
| 25 | |
| 26 | |
| 27 | <?php |
| 28 | |
| 29 | if ( is_plugin_active('auxin-elements/auxin-elements.php') ) { |
| 30 | |
| 31 | remove_action( 'woocommerce_shop_loop_item_title', 'auxin_woocommerce_template_loop_product_title', 10 ); |
| 32 | } |
| 33 | |
| 34 | if(is_plugin_active('auxin-shop/auxin-shop.php')) { |
| 35 | |
| 36 | remove_action( 'woocommerce_after_shop_loop_item_title', 'auxshp_loop_product_meta', 12 ); |
| 37 | remove_action( 'woocommerce_after_shop_loop_item' , 'auxshp_loop_product_tools', 12 ); |
| 38 | remove_action( 'woocommerce_archive_description' , 'auxshp_archive_page_title_description', 1 ); |
| 39 | remove_action( 'woocommerce_before_shop_loop_item_title', 'auxshp_get_product_thumbnail', 11 ); |
| 40 | } |
| 41 | ?> |
| 42 | |
| 43 | <?php |
| 44 | //Blocksy theme conflict issue |
| 45 | $themeName = get_template(); |
| 46 | if($themeName == 'blocksy'):?> |
| 47 | <?php remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); ?> |
| 48 | <?php remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_rating', 20); ?> |
| 49 | <?php endif; |
| 50 | ?> |
| 51 | |
| 52 | <?php |
| 53 | //Eduma theme conflict |
| 54 | $themeName = get_template(); |
| 55 | if($themeName == 'eduma'):?> |
| 56 | <?php remove_filter('loop_shop_columns', '__return_false'); ?> |
| 57 | <?php endif; |
| 58 | ?> |
| 59 | <?php |
| 60 | |
| 61 | if(!function_exists('custom_shopengine_product_title')) { |
| 62 | function custom_shopengine_product_title($header_size, $settings) { |
| 63 | global $product; |
| 64 | |
| 65 | $title = get_the_title($product->get_id()); |
| 66 | |
| 67 | // Handle word limit if excerpt is enabled |
| 68 | if (isset($settings['shopengine_title_excerpt_enable']) && |
| 69 | $settings['shopengine_title_excerpt_enable'] === 'yes' && |
| 70 | isset($settings['shopengine_title_excerpt_length'])) { |
| 71 | $word_limit = (int) $settings['shopengine_title_excerpt_length']; |
| 72 | $title = wp_trim_words($title, $word_limit, '...'); |
| 73 | } |
| 74 | |
| 75 | shopengine_content_render( |
| 76 | sprintf( |
| 77 | '<%1$s class="woocommerce-loop-product__title">%2$s</%1$s>', |
| 78 | esc_attr($header_size), |
| 79 | esc_html($title) |
| 80 | ) |
| 81 | ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Remove the default WooCommerce title hook and add the custom title function |
| 86 | remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10); |
| 87 | add_action('woocommerce_shop_loop_item_title', function() use ($settings_to_pass) { |
| 88 | $header_size = isset($settings_to_pass['shopengine_archive_product_title_header_size']) ? $settings_to_pass['shopengine_archive_product_title_header_size'] : 'h1'; |
| 89 | if (function_exists('custom_shopengine_product_title')) { |
| 90 | custom_shopengine_product_title($header_size, $settings_to_pass); |
| 91 | } |
| 92 | }, 10); |
| 93 | |
| 94 | ?> |
| 95 | <div data-pagination="<?php echo esc_attr($shopengine_pagination_style) ?>" |
| 96 | class="shopengine-archive-products <?php echo esc_attr($wrap_extra_class); ?> <?php echo (isset($shopengine_independent_add_to_cart) && $shopengine_independent_add_to_cart === 'yes' && isset($shopengine_independent_add_to_cart_position) && $shopengine_independent_add_to_cart_position === 'top') ? 'shopengine-independent-add-to-cart-position-top' : ''; ?>"> |
| 97 | <?php |
| 98 | // add product description |
| 99 | add_action('woocommerce_after_shop_loop_item_title', function () use ($shopengine_is_details, $shopengine_group_btns, $shopengine_independent_add_to_cart, $shopengine_independent_add_to_cart_position, $shopengine_is_hover_details) { |
| 100 | $has_group_buttons = ($shopengine_group_btns === 'yes'); |
| 101 | $has_independent = (isset($shopengine_independent_add_to_cart) && $shopengine_independent_add_to_cart === 'yes'); |
| 102 | $show_indep_bottom = $has_independent && isset($shopengine_independent_add_to_cart_position) && $shopengine_independent_add_to_cart_position === 'bottom'; |
| 103 | $show_default_buttons = !$has_group_buttons && !$has_independent; |
| 104 | $show_description = ($shopengine_is_details === 'yes') && $show_default_buttons; |
| 105 | $show_footer = $show_description || $show_indep_bottom || $show_default_buttons; |
| 106 | |
| 107 | $footer_classes = 'shopengine-product-description-footer'; |
| 108 | if ($shopengine_is_hover_details === 'yes') { |
| 109 | $footer_classes .= ' shopengine-product-description-footer-hover'; |
| 110 | } |
| 111 | if ($has_independent) { |
| 112 | $footer_classes .= ' shopengine-independent-add-to-cart'; |
| 113 | } |
| 114 | |
| 115 | if ($show_footer) : ?> |
| 116 | <div class="<?php echo esc_attr($footer_classes); ?>"> |
| 117 | <?php endif; |
| 118 | |
| 119 | if ($show_description) : ?> |
| 120 | <div class="shopengine-product-excerpt"> <?php the_excerpt(); ?> </div> |
| 121 | <?php endif; |
| 122 | |
| 123 | if ($show_indep_bottom) : ?> |
| 124 | <div class="shopengine-product-description-btn-group shopengine-independent-add-to-cart shopengine-cart-only"> |
| 125 | <?php woocommerce_template_loop_add_to_cart(); ?> |
| 126 | </div> |
| 127 | <?php elseif ($show_default_buttons) : ?> |
| 128 | <div class="shopengine-product-description-btn-group default-btns <?php echo esc_attr($this->get_button_hide_classes()); ?>"> |
| 129 | <?php $this->render_footer_action_btns(); ?> |
| 130 | </div> |
| 131 | <?php endif; |
| 132 | |
| 133 | if ($show_footer) : ?> |
| 134 | </div> |
| 135 | <?php endif; |
| 136 | |
| 137 | }, 40); |
| 138 | |
| 139 | // If independent position is 'top', render add-to-cart in the image area (before title) |
| 140 | if (isset($shopengine_independent_add_to_cart) && $shopengine_independent_add_to_cart === 'yes') { |
| 141 | add_action('woocommerce_before_shop_loop_item_title', function () use ($shopengine_independent_add_to_cart, $shopengine_independent_add_to_cart_position, $shopengine_group_btns) { |
| 142 | if (isset($shopengine_independent_add_to_cart_position) && $shopengine_independent_add_to_cart_position === 'top') : |
| 143 | woocommerce_template_loop_product_link_close(); |
| 144 | ?> |
| 145 | <div class="shopengine-product-thumb-add-to-cart shopengine-independent-add-to-cart shopengine-cart-only"> |
| 146 | <?php woocommerce_template_loop_add_to_cart(); ?> |
| 147 | </div> |
| 148 | <?php |
| 149 | woocommerce_template_loop_product_link_open(); |
| 150 | endif; |
| 151 | }, 20); |
| 152 | } |
| 153 | |
| 154 | // Editor mode product query args for pagination and product count based on customizer settings. On frontend, it will use the default query. |
| 155 | |
| 156 | if ( $editor_mode ) { |
| 157 | $per_page = (int) get_option('posts_per_page'); |
| 158 | $paged = max(1, (int) get_query_var('paged'), (int) get_query_var('page')); |
| 159 | $wp_query_args = [ |
| 160 | 'post_type' => 'product', |
| 161 | 'posts_per_page' => $per_page, |
| 162 | 'paged' => $paged, |
| 163 | 'post_status' => 'publish', |
| 164 | 'tax_query' => [ |
| 165 | [ |
| 166 | 'taxonomy' => 'product_visibility', |
| 167 | 'field' => 'name', |
| 168 | 'terms' => ['exclude-from-catalog'], |
| 169 | 'operator' => 'NOT IN', |
| 170 | ], |
| 171 | ], |
| 172 | ]; |
| 173 | } else { |
| 174 | $wp_query_args = ['post_type' => 'product']; |
| 175 | } |
| 176 | |
| 177 | // pagination next previous button label filter |
| 178 | |
| 179 | if($shopengine_pagination_style === 'numeric') { |
| 180 | $control_args['prev_icon'] = '<i class="' . esc_attr($shopengine_pagination_prev_icon['value']) . '"></i>'; |
| 181 | $control_args['next_icon'] = '<i class="' . esc_attr($shopengine_pagination_next_icon['value']) . '"></i>'; |
| 182 | } |
| 183 | |
| 184 | if($shopengine_pagination_style === 'default') { |
| 185 | $control_args['prev_icon'] = $shopengine_pagination_prev_text; |
| 186 | $control_args['next_icon'] = $shopengine_pagination_next_text; |
| 187 | } |
| 188 | |
| 189 | if($shopengine_pagination_style === 'load-more' || $shopengine_pagination_style === 'load-more-on-scroll') { |
| 190 | $control_args['prev_icon'] = ''; |
| 191 | $control_args['next_icon'] = $shopengine_pagination_loadmore_text; |
| 192 | } |
| 193 | |
| 194 | if(isset($control_args)) { |
| 195 | add_filter('woocommerce_pagination_args', function ($args) use ($control_args) { |
| 196 | $args['prev_text'] = $control_args['prev_icon']; |
| 197 | $args['next_text'] = $control_args['next_icon']; |
| 198 | |
| 199 | return $args; |
| 200 | }); |
| 201 | } |
| 202 | |
| 203 | $page_type = \ShopEngine\Widgets\Products::instance()->get_template_type_by_id(get_the_ID()); |
| 204 | if(in_array($page_type, ['archive', 'shop', 'search']) && $editor_mode) { |
| 205 | |
| 206 | global $wp_query, $post; |
| 207 | $main_query = clone $wp_query; |
| 208 | $main_post = clone $post; |
| 209 | $wp_query = new \WP_Query($wp_query_args); |
| 210 | wc_setup_loop( |
| 211 | [ |
| 212 | 'is_filtered' => is_filtered(), |
| 213 | 'total' => $wp_query->found_posts, |
| 214 | 'total_pages' => $wp_query->max_num_pages, |
| 215 | 'per_page' => $wp_query->get('posts_per_page'), |
| 216 | 'current_page' => max(1, $wp_query->get('paged', 1)), |
| 217 | ] |
| 218 | ); |
| 219 | } |
| 220 | |
| 221 | $run_loop = $editor_mode ? true : (is_shop() || is_archive() ? woocommerce_product_loop() : false); |
| 222 | if( $editor_mode ) { |
| 223 | |
| 224 | if(empty(WC()->session)) { |
| 225 | WC()->session = new WC_Session_Handler(); |
| 226 | WC()->session->init(); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | //this option will come from Customizer > Woocmmerce > Product catelog > Products per row in mobile |
| 231 | $custom_catalog_option = get_theme_mod('shopengine_product_per_page_mobile', '2'); |
| 232 | $custom_catalog_option_tablet = get_theme_mod('shopengine_product_per_page_tablet', '2'); |
| 233 | |
| 234 | $style = " |
| 235 | :root{ |
| 236 | --shopengine-product-row-mobile : $custom_catalog_option; |
| 237 | --shopengine-product-row-tablet : $custom_catalog_option_tablet; |
| 238 | } |
| 239 | "; |
| 240 | |
| 241 | if ($columns = get_option('woocommerce_catalog_columns')) { |
| 242 | $style = " |
| 243 | :root{ |
| 244 | --wc-product-column : $columns; |
| 245 | --shopengine-product-row-mobile : $custom_catalog_option; |
| 246 | --shopengine-product-row-tablet : $custom_catalog_option_tablet; |
| 247 | } |
| 248 | "; |
| 249 | } |
| 250 | shopengine_content_render("<style>$style</style>"); |
| 251 | |
| 252 | |
| 253 | if(wc_is_active_theme('kadence')):?> |
| 254 | <div class="product-details"> </div> |
| 255 | <?php endif; |
| 256 | |
| 257 | $tooltip = !empty($settings['shopengine_is_tooltip']) ? $settings['shopengine_is_tooltip'] : ''; |
| 258 | if($run_loop) { |
| 259 | |
| 260 | do_action('woocommerce_before_shop_loop'); |
| 261 | |
| 262 | woocommerce_product_loop_start(); |
| 263 | |
| 264 | if(wc_get_loop_prop('total')) { |
| 265 | while(have_posts()) { |
| 266 | the_post(); |
| 267 | |
| 268 | /** |
| 269 | * Hook: woocommerce_shop_loop. |
| 270 | */ |
| 271 | do_action('woocommerce_shop_loop'); |
| 272 | |
| 273 | global $product; |
| 274 | |
| 275 | // Ensure visibility. |
| 276 | if ( ! empty( $product ) && $product->is_visible() ) : ?> |
| 277 | |
| 278 | <li class="archive-product-container" data-tooltip="<?php echo esc_attr($tooltip); ?>"> |
| 279 | <ul class="shopengine-archive-mode-grid"> |
| 280 | <li class="shopengine-archive-products__left-image" > |
| 281 | <a title="<?php esc_html_e('Archive Product Left Image','shopengine')?>" href="<?php echo esc_url( get_the_permalink() ); ?>"> |
| 282 | <?php shopengine_content_render( woocommerce_get_product_thumbnail( get_the_id() ) )?> |
| 283 | </a> |
| 284 | </li> |
| 285 | |
| 286 | <?php wc_get_template_part('content', 'product');?> |
| 287 | |
| 288 | </ul> |
| 289 | </li> |
| 290 | <?php endif; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | woocommerce_product_loop_end(); |
| 295 | |
| 296 | /** |
| 297 | * Hook: woocommerce_after_shop_loop. |
| 298 | * |
| 299 | * @hooked woocommerce_pagination - 10 |
| 300 | */ |
| 301 | do_action('woocommerce_after_shop_loop'); |
| 302 | |
| 303 | } else { |
| 304 | /** |
| 305 | * Hook: woocommerce_no_products_found. |
| 306 | * |
| 307 | * @hooked wc_no_products_found - 10 |
| 308 | */ |
| 309 | do_action('woocommerce_no_products_found'); |
| 310 | } |
| 311 | |
| 312 | if(in_array($page_type, ['archive', 'shop', 'search']) && $editor_mode) { |
| 313 | $wp_query = $main_query; |
| 314 | $post = $main_post; |
| 315 | wp_reset_query(); |
| 316 | wp_reset_postdata(); |
| 317 | } |
| 318 | ?> |
| 319 | </div> |
| 320 |