default.php
244 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Template Name: Default |
| 5 | */ |
| 6 | |
| 7 | use \Essential_Addons_Elementor\Classes\Helper; |
| 8 | use Essential_Addons_Elementor\Elements\Woo_Product_Gallery; |
| 9 | use \Elementor\Group_Control_Image_Size; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } // Exit if accessed directly |
| 14 | |
| 15 | $product = wc_get_product( get_the_ID() ); |
| 16 | if ( ! $product ) { |
| 17 | error_log( '$product not found in ' . __FILE__ ); |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | if ( has_post_thumbnail() ) { |
| 22 | $settings[ 'eael_image_size_customize' ] = [ |
| 23 | 'id' => get_post_thumbnail_id(), |
| 24 | ]; |
| 25 | $settings['eael_image_size_customize_size'] = $settings['eael_product_gallery_image_size_size']; |
| 26 | $thumbnail_html = Group_Control_Image_Size::get_attachment_image_html( $settings,'eael_image_size_customize' ); |
| 27 | } |
| 28 | |
| 29 | $title_tag = isset( $settings['eael_product_gallery_title_html_tag'] ) ? Helper::eael_validate_html_tag($settings['eael_product_gallery_title_html_tag']) : 'h2'; |
| 30 | |
| 31 | // Improvement |
| 32 | $gallery_style_preset = isset($settings['eael_product_gallery_style_preset']) ? $settings['eael_product_gallery_style_preset'] : ''; |
| 33 | $sale_badge_align = isset( $settings['eael_product_sale_badge_alignment'] ) ? $settings['eael_product_sale_badge_alignment'] : ''; |
| 34 | $sale_badge_preset = isset($settings['eael_product_sale_badge_preset']) ? $settings['eael_product_sale_badge_preset'] : ''; |
| 35 | // should print vars |
| 36 | $sale_text = !empty($settings['eael_product_gallery_sale_text']) ? $settings['eael_product_gallery_sale_text'] : 'Sale!'; |
| 37 | $stockout_text = !empty($settings['eael_product_gallery_stockout_text']) ? $settings['eael_product_gallery_stockout_text'] : 'Stock <br/> Out'; |
| 38 | $should_print_rating = isset( $settings['eael_product_gallery_rating'] ) && 'yes' === $settings['eael_product_gallery_rating']; |
| 39 | $should_print_quick_view = isset( $settings['eael_product_gallery_quick_view'] ) && 'yes' === $settings['eael_product_gallery_quick_view']; |
| 40 | $should_print_addtocart = isset( $settings['eael_product_gallery_addtocart_show'] ) && 'yes' === $settings['eael_product_gallery_addtocart_show']; |
| 41 | $should_print_link = isset( $settings['eael_product_gallery_link_show'] ) && 'yes' === $settings['eael_product_gallery_link_show']; |
| 42 | $should_print_image_clickable = isset( $settings['eael_product_gallery_image_clickable'] ) && 'yes' === $settings['eael_product_gallery_image_clickable']; |
| 43 | $should_print_price = isset( $settings['eael_product_gallery_price'] ) && 'yes' === $settings['eael_product_gallery_price']; |
| 44 | $widget_id = isset($settings['eael_widget_id']) ? $settings['eael_widget_id'] : null; |
| 45 | $quick_view_setting = [ |
| 46 | 'widget_id' => $widget_id, |
| 47 | 'product_id' => $product->get_id(), |
| 48 | 'page_id' => $settings['eael_page_id'], |
| 49 | ]; |
| 50 | |
| 51 | $show_secondary_image = isset( $settings['eael_product_gallery_show_secondary_image'] ) && 'yes' === $settings['eael_product_gallery_show_secondary_image']; |
| 52 | $image_sources = [ |
| 53 | 'src' => '', |
| 54 | 'src_hover' => '' |
| 55 | ]; |
| 56 | //if ( true === wc_get_loop_product_visibility( $product->get_id() ) || $product->is_visible() ) { |
| 57 | |
| 58 | if ( $gallery_style_preset == 'eael-product-preset-4' ) { ?> |
| 59 | <li class="product"> |
| 60 | <?php |
| 61 | if($show_secondary_image){ |
| 62 | $image_sources = Helper::eael_get_woo_product_gallery_image_srcs( $product, $settings['eael_product_gallery_image_size_size'] ); |
| 63 | } |
| 64 | ?> |
| 65 | <div class="eael-product-wrap" data-src="<?php echo esc_attr( $image_sources['src'] ) ?>" data-src-hover="<?php echo esc_attr( $image_sources['src_hover'] ) ?>" > |
| 66 | <?php |
| 67 | echo ( ! $product->is_in_stock() ? '<span class="eael-onsale outofstock '.$sale_badge_preset.' '.$sale_badge_align.'">'. Helper::eael_wp_kses($stockout_text) .'</span>' : ($product->is_on_sale() ? '<span class="eael-onsale '.$sale_badge_preset.' '.$sale_badge_align.'">' . Helper::eael_wp_kses($sale_text) . '</span>' : '') ); |
| 68 | |
| 69 | if( $should_print_image_clickable ) { |
| 70 | echo '<a href="' . $product->get_permalink() . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">'; |
| 71 | }?> |
| 72 | <?php |
| 73 | // echo wp_kses_post( $product->get_image( 'woocommerce_thumbnail', ['loading' => 'eager'] ) ); |
| 74 | echo wp_kses_post( $product->get_image( $settings['eael_product_gallery_image_size_size'], ['loading' => 'eager'] ) ); |
| 75 | if ( $should_print_image_clickable ) { |
| 76 | echo '</a>'; |
| 77 | } |
| 78 | printf('<%1$s class="woocommerce-loop-product__title">%2$s</%1$s>', $title_tag, Helper::eael_wp_kses($product->get_title())); |
| 79 | if ( $should_print_rating ) { |
| 80 | echo wp_kses_post( wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ) ); |
| 81 | } |
| 82 | |
| 83 | if ( $should_print_price ) { |
| 84 | echo '<div class="eael-product-price">'.$product->get_price_html().'</div>'; |
| 85 | } |
| 86 | ?> |
| 87 | <?php |
| 88 | if ( $should_print_addtocart ) { |
| 89 | woocommerce_template_loop_add_to_cart(); |
| 90 | } ?> |
| 91 | </div> |
| 92 | </li> |
| 93 | <?php |
| 94 | } else if (($gallery_style_preset == 'eael-product-preset-3') || ($gallery_style_preset == 'eael-product-preset-2')) { |
| 95 | ?> |
| 96 | <li <?php post_class( 'product' ); ?>> |
| 97 | <?php |
| 98 | if( $show_secondary_image ){ |
| 99 | $image_sources = Helper::eael_get_woo_product_gallery_image_srcs( $product, $settings['eael_product_gallery_image_size_size'] ); |
| 100 | } |
| 101 | |
| 102 | ?> |
| 103 | <div class="eael-product-wrap" data-src="<?php echo esc_attr( $image_sources['src'] ) ?>" data-src-hover="<?php echo esc_attr( $image_sources['src_hover'] ) ?>" > |
| 104 | <div class="product-image-wrap"> |
| 105 | <div class="image-wrap"> |
| 106 | <?php if( $should_print_image_clickable ) { |
| 107 | echo '<a href="' . $product->get_permalink() . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">'; |
| 108 | }?> |
| 109 | <?php |
| 110 | echo ( ! $product->is_in_stock() ? '<span class="eael-onsale outofstock '.$sale_badge_preset.' '.$sale_badge_align.'">'. Helper::eael_wp_kses( $stockout_text ) .'</span>' : ($product->is_on_sale() ? '<span class="eael-onsale '.$sale_badge_preset.' '.$sale_badge_align.'">' . Helper::eael_wp_kses($sale_text) . '</span>' : '') ); |
| 111 | echo $product->get_image($settings['eael_product_gallery_image_size_size'], ['loading' => 'eager']); |
| 112 | ?> |
| 113 | <?php if( $should_print_image_clickable ) { |
| 114 | echo '</a>'; |
| 115 | }?> |
| 116 | </div> |
| 117 | <div class="image-hover-wrap"> |
| 118 | <?php if ($gallery_style_preset == 'eael-product-preset-2') { ?> |
| 119 | <ul class="icons-wrap block-box-style"> |
| 120 | <?php if( $should_print_addtocart ){?> |
| 121 | <li class="add-to-cart"><?php woocommerce_template_loop_add_to_cart(); ?></li> |
| 122 | <?php } ?> |
| 123 | <?php if( $should_print_quick_view ){?> |
| 124 | <li class="eael-product-quick-view"> |
| 125 | <a id="eael_quick_view_<?php echo uniqid(); ?>" data-quickview-setting="<?php echo htmlspecialchars(json_encode($quick_view_setting),ENT_QUOTES); ?>" |
| 126 | class="eael-product-gallery-open-popup open-popup-link"> |
| 127 | <i class="fas fa-eye"></i> |
| 128 | </a> |
| 129 | </li> |
| 130 | <?php } ?> |
| 131 | <?php if( $should_print_link ){?> |
| 132 | <li class="view-details"><?php echo '<a href="' . $product->get_permalink |
| 133 | () . '"><i class="fas fa-link"></i></a>'; ?></li> |
| 134 | <?php } ?> |
| 135 | </ul> |
| 136 | <?php } else { ?> |
| 137 | <ul class="icons-wrap box-style"> |
| 138 | <?php if( $should_print_addtocart ){?> |
| 139 | <li class="add-to-cart"><?php woocommerce_template_loop_add_to_cart(); ?></li> |
| 140 | <?php } ?> |
| 141 | |
| 142 | <?php if( $should_print_quick_view ){?> |
| 143 | <li class="eael-product-quick-view"> |
| 144 | <a id="eael_quick_view_<?php echo uniqid(); ?>" data-quickview-setting="<?php echo htmlspecialchars(json_encode($quick_view_setting),ENT_QUOTES); ?>" |
| 145 | class="eael-product-gallery-open-popup open-popup-link"> |
| 146 | <i class="fas fa-eye"></i> |
| 147 | </a> |
| 148 | </li> |
| 149 | <?php } ?> |
| 150 | |
| 151 | <?php if( $should_print_link ){?> |
| 152 | <li class="view-details" title="Details"><?php echo '<a href="' . $product->get_permalink() . '"><i class="fas fa-link"></i></a>'; ?></li> |
| 153 | <?php } ?> |
| 154 | </ul> |
| 155 | <?php } |
| 156 | ?> |
| 157 | </div> |
| 158 | </div> |
| 159 | <div class="product-details-wrap"> |
| 160 | <?php |
| 161 | if(($gallery_style_preset == 'eael-product-preset-2') && $should_print_price ){ |
| 162 | echo '<div class="eael-product-price">'.$product->get_price_html().'</div>'; |
| 163 | } |
| 164 | |
| 165 | if ($should_print_rating) { |
| 166 | echo wc_get_rating_html |
| 167 | ($product->get_average_rating(), $product->get_rating_count()); |
| 168 | } |
| 169 | ?> |
| 170 | <div class="eael-product-title"> |
| 171 | <?php printf('<%1$s>%2$s</%1$s>', $title_tag, Helper::eael_wp_kses($product->get_title())); ?> |
| 172 | </div> |
| 173 | <?php if(($gallery_style_preset != 'eael-product-preset-2') && $should_print_price ){ |
| 174 | echo '<div class="eael-product-price">'.$product->get_price_html().'</div>'; |
| 175 | }?> |
| 176 | </div> |
| 177 | </div> |
| 178 | </li> |
| 179 | <?php |
| 180 | |
| 181 | } else if ($gallery_style_preset == 'eael-product-preset-1') { |
| 182 | ?> |
| 183 | <li <?php post_class( 'product' ); ?>> |
| 184 | <?php |
| 185 | if( $show_secondary_image ){ |
| 186 | $image_sources = Helper::eael_get_woo_product_gallery_image_srcs( $product, $settings['eael_product_gallery_image_size_size'] ); |
| 187 | } |
| 188 | ?> |
| 189 | <div class="eael-product-wrap" data-src="<?php echo esc_attr( $image_sources['src'] ) ?>" data-src-hover="<?php echo esc_attr( $image_sources['src_hover'] ) ?>" > |
| 190 | <div class="product-image-wrap"> |
| 191 | <div class="image-wrap"> |
| 192 | <?php if( $should_print_image_clickable ) { |
| 193 | echo '<a href="' . $product->get_permalink() . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">'; |
| 194 | }?> |
| 195 | |
| 196 | <?php |
| 197 | echo ( ! $product->is_in_stock() ? '<span class="eael-onsale outofstock '.$sale_badge_preset.' '.$sale_badge_align.'">'. Helper::eael_wp_kses($stockout_text) .'</span>' : ($product->is_on_sale() ? '<span class="eael-onsale '.$sale_badge_preset.' '.$sale_badge_align.'">' . Helper::eael_wp_kses($sale_text) . '</span>' : '') ); |
| 198 | echo $product->get_image($settings['eael_product_gallery_image_size_size'], ['loading' => 'eager']); |
| 199 | ?> |
| 200 | <?php if( $should_print_image_clickable ) { |
| 201 | echo '</a>'; |
| 202 | }?> |
| 203 | </div> |
| 204 | <div class="image-hover-wrap"> |
| 205 | <ul class="icons-wrap over-box-style"> |
| 206 | <?php if( $should_print_addtocart ){?> |
| 207 | <li class="add-to-cart"><?php woocommerce_template_loop_add_to_cart(); ?></li> |
| 208 | <?php } ?> |
| 209 | <?php if( $should_print_quick_view ){?> |
| 210 | <li class="eael-product-quick-view"> |
| 211 | <a id="eael_quick_view_<?php echo uniqid(); ?>" data-quickview-setting="<?php echo htmlspecialchars(json_encode($quick_view_setting),ENT_QUOTES); ?>" |
| 212 | class="eael-product-gallery-open-popup open-popup-link"> |
| 213 | <i class="fas fa-eye"></i> |
| 214 | </a> |
| 215 | </li> |
| 216 | <?php } ?> |
| 217 | <?php if( $should_print_link ){?> |
| 218 | <li class="view-details"><?php echo '<a href="' . $product->get_permalink |
| 219 | () . '"><i class="fas fa-link"></i></a>'; ?></li> |
| 220 | <?php } ?> |
| 221 | </ul> |
| 222 | </div> |
| 223 | </div> |
| 224 | <div class="product-details-wrap"> |
| 225 | <?php |
| 226 | if ( $should_print_price ) { |
| 227 | echo '<div class="eael-product-price">'.$product->get_price_html().'</div>'; |
| 228 | } |
| 229 | ?> |
| 230 | <div class="eael-product-title"> |
| 231 | <?php |
| 232 | echo '<a href="' . $product->get_permalink() . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">'; |
| 233 | printf('<%1$s>%2$s</%1$s>', $title_tag, Helper::eael_wp_kses($product->get_title())); |
| 234 | echo '</a>'; |
| 235 | ?> |
| 236 | </div> |
| 237 | </div> |
| 238 | </div> |
| 239 | </li> |
| 240 | <?php |
| 241 | |
| 242 | } |
| 243 | //} |
| 244 |