default.php
298 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 | $product_wrapper_classes = implode( " ", apply_filters( 'eael_product_wrapper_class', [], $product->get_id(), 'woo-product-gallery' ) ); |
| 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 | $product_data = [ |
| 57 | 'title' => sprintf( '<%1$s class="woocommerce-loop-product__title">%2$s</%1$s>', $title_tag, $product->get_title() ), |
| 58 | 'price' => $should_print_price ? '<div class="eael-product-price">' . $product->get_price_html() . '</div>' : '', |
| 59 | 'ratings' => '', |
| 60 | ]; |
| 61 | |
| 62 | if ( $should_print_rating ) { |
| 63 | $avg_rating = $product->get_average_rating(); |
| 64 | if( $avg_rating > 0 ){ |
| 65 | $product_data['ratings'] = wc_get_rating_html( $avg_rating, $product->get_rating_count()); |
| 66 | } else { |
| 67 | $product_data['ratings'] = Helper::eael_rating_markup( $avg_rating, $product->get_rating_count() ); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if ( $gallery_style_preset == 'eael-product-preset-4' ) { ?> |
| 72 | <li class="product"> |
| 73 | <?php |
| 74 | if($show_secondary_image){ |
| 75 | $image_sources = Helper::eael_get_woo_product_gallery_image_srcs( $product, $settings['eael_product_gallery_image_size_size'] ); |
| 76 | } |
| 77 | ?> |
| 78 | <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'] ) ?>" > |
| 79 | <?php |
| 80 | do_action( 'eael_woocommerce_before_shop_loop_item' ); |
| 81 | if ( $settings['eael_wc_loop_hooks'] === 'yes' ){ |
| 82 | do_action( 'woocommerce_before_shop_loop_item' ); |
| 83 | } |
| 84 | |
| 85 | echo ( ! $product->is_in_stock() ? '<span class="eael-onsale outofstock '. esc_attr( $sale_badge_preset . ' ' . $sale_badge_align ) .'">'. $stockout_text .'</span>' : ($product->is_on_sale() ? '<span class="eael-onsale '. esc_attr( $sale_badge_preset . ' ' . $sale_badge_align ) .'">' . $sale_text . '</span>' : '') ); |
| 86 | |
| 87 | if( $should_print_image_clickable ) { |
| 88 | echo '<a href="' . $product->get_permalink() . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">'; |
| 89 | }?> |
| 90 | <?php |
| 91 | echo $product->get_image( $settings['eael_product_gallery_image_size_size'], ['loading' => 'eager', 'alt' => esc_attr( $product->get_title() ) ] ); |
| 92 | if ( $should_print_image_clickable ) { |
| 93 | echo '</a>'; |
| 94 | } |
| 95 | |
| 96 | $product_data = apply_filters( 'eael/product-gallery/content/reordering', $product_data, $settings, $product ); |
| 97 | if ( ! empty( $product_data ) ) { |
| 98 | foreach ( $product_data as $content ) { |
| 99 | if ( ! empty( $content ) ) { |
| 100 | echo wp_kses( $content, Helper::eael_allowed_tags(), Helper::eael_allowed_protocols() ); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | ?> |
| 105 | <?php |
| 106 | if ( $should_print_addtocart ) { |
| 107 | woocommerce_template_loop_add_to_cart(); |
| 108 | } |
| 109 | if ( $settings['eael_wc_loop_hooks'] === 'yes' ){ |
| 110 | do_action( 'woocommerce_after_shop_loop_item' ); |
| 111 | } |
| 112 | do_action( 'eael_woocommerce_after_shop_loop_item' ); |
| 113 | ?> </div> |
| 114 | </li> |
| 115 | <?php |
| 116 | } |
| 117 | else if (($gallery_style_preset == 'eael-product-preset-3') || ($gallery_style_preset == 'eael-product-preset-2')) { |
| 118 | ?> |
| 119 | <li <?php post_class( "product {$product_wrapper_classes}" ); ?>> |
| 120 | <?php |
| 121 | if( $show_secondary_image ){ |
| 122 | $image_sources = Helper::eael_get_woo_product_gallery_image_srcs( $product, $settings['eael_product_gallery_image_size_size'] ); |
| 123 | } |
| 124 | |
| 125 | ?> |
| 126 | <div class="eael-product-wrap" data-src="<?php echo esc_url( $image_sources['src'] ); ?>" data-src-hover="<?php echo esc_url( $image_sources['src_hover'] ); ?>" > |
| 127 | <?php |
| 128 | do_action( 'eael_woocommerce_before_shop_loop_item' ); |
| 129 | if ( $settings['eael_wc_loop_hooks'] === 'yes' ) { |
| 130 | do_action( 'woocommerce_before_shop_loop_item' ); |
| 131 | } |
| 132 | ?> |
| 133 | <div class="product-image-wrap"> |
| 134 | <div class="image-wrap"> |
| 135 | <?php if( $should_print_image_clickable ) { |
| 136 | echo '<a href="' . $product->get_permalink() . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">'; |
| 137 | } |
| 138 | |
| 139 | echo ( ! $product->is_in_stock() ? '<span class="eael-onsale outofstock '. esc_attr( $sale_badge_preset . ' ' . $sale_badge_align ) .'">'. $stockout_text .'</span>' : ($product->is_on_sale() ? '<span class="eael-onsale '. esc_attr( $sale_badge_preset . ' ' . $sale_badge_align ) .'">' . wp_kses( $sale_text, Helper::eael_allowed_tags() ) . '</span>' : '') ); |
| 140 | echo $product->get_image($settings['eael_product_gallery_image_size_size'], ['loading' => 'eager', 'alt' => esc_attr( $product->get_title() )]); |
| 141 | |
| 142 | if( $should_print_image_clickable ) { |
| 143 | echo '</a>'; |
| 144 | }?> |
| 145 | </div> |
| 146 | <div class="image-hover-wrap"> |
| 147 | <?php if ($gallery_style_preset == 'eael-product-preset-2') { ?> |
| 148 | <ul class="icons-wrap block-box-style"> |
| 149 | <?php if( $should_print_addtocart ){?> |
| 150 | <li class="add-to-cart"><?php woocommerce_template_loop_add_to_cart(); ?></li> |
| 151 | <?php } ?> |
| 152 | <?php if( $should_print_quick_view ){?> |
| 153 | <li class="eael-product-quick-view"> |
| 154 | <a id="eael_quick_view_<?php echo uniqid(); ?>" data-quickview-setting="<?php echo htmlspecialchars(json_encode($quick_view_setting),ENT_QUOTES); ?>" |
| 155 | class="eael-product-gallery-open-popup open-popup-link"> |
| 156 | <i class="fas fa-eye"></i> |
| 157 | </a> |
| 158 | </li> |
| 159 | <?php } ?> |
| 160 | <?php if( $should_print_link ){?> |
| 161 | <li class="view-details"><?php echo '<a href="' . $product->get_permalink |
| 162 | () . '" aria-label="View Details about ' . esc_attr( $product->get_title() ). '"><i class="fas fa-link"></i></a>'; ?></li> |
| 163 | <?php } ?> |
| 164 | </ul> |
| 165 | <?php } else { ?> |
| 166 | <ul class="icons-wrap box-style"> |
| 167 | <?php if( $should_print_addtocart ){?> |
| 168 | <li class="add-to-cart"><?php woocommerce_template_loop_add_to_cart(); ?></li> |
| 169 | <?php } ?> |
| 170 | |
| 171 | <?php if( $should_print_quick_view ){?> |
| 172 | <li class="eael-product-quick-view"> |
| 173 | <a id="eael_quick_view_<?php echo uniqid(); ?>" data-quickview-setting="<?php echo htmlspecialchars(json_encode($quick_view_setting),ENT_QUOTES); ?>" |
| 174 | class="eael-product-gallery-open-popup open-popup-link"> |
| 175 | <i class="fas fa-eye"></i> |
| 176 | </a> |
| 177 | </li> |
| 178 | <?php } ?> |
| 179 | |
| 180 | <?php if( $should_print_link ){?> |
| 181 | <li class="view-details" title="Details" aria-label="View Details about <?php echo esc_attr( $product->get_title() ); ?>"><?php echo '<a href="' . $product->get_permalink() . '"><i class="fas fa-link"></i></a>'; ?></li> |
| 182 | <?php } ?> |
| 183 | </ul> |
| 184 | <?php } |
| 185 | ?> |
| 186 | </div> |
| 187 | </div> |
| 188 | <div class="product-details-wrap"> |
| 189 | <?php |
| 190 | $_product_data = []; |
| 191 | if($gallery_style_preset == 'eael-product-preset-2' ){ |
| 192 | $_product_data['price'] = $product_data['price']; |
| 193 | } |
| 194 | |
| 195 | $_product_data['ratings'] = $product_data['ratings']; |
| 196 | $_product_data['title'] = $product_data['title']; |
| 197 | |
| 198 | if( $gallery_style_preset != 'eael-product-preset-2' ){ |
| 199 | $_product_data['price'] = $product_data['price']; |
| 200 | } |
| 201 | |
| 202 | $product_data = apply_filters( 'eael/product-gallery/content/reordering', $_product_data, $settings, $product ); |
| 203 | if ( ! empty( $product_data ) ) { |
| 204 | foreach ( $product_data as $content ) { |
| 205 | if ( ! empty( $content ) ) { |
| 206 | echo wp_kses( $content, Helper::eael_allowed_tags(), Helper::eael_allowed_protocols() ); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | ?> |
| 211 | </div> |
| 212 | <?php |
| 213 | if ( $settings['eael_wc_loop_hooks'] === 'yes' ) { |
| 214 | do_action( 'woocommerce_after_shop_loop_item' ); |
| 215 | } |
| 216 | do_action( 'eael_woocommerce_after_shop_loop_item' ); |
| 217 | ?> |
| 218 | </div> |
| 219 | </li> |
| 220 | <?php |
| 221 | } |
| 222 | else if ($gallery_style_preset == 'eael-product-preset-1') { |
| 223 | ?> |
| 224 | <li <?php post_class( "product {$product_wrapper_classes}" ); ?>> |
| 225 | <?php |
| 226 | if( $show_secondary_image ){ |
| 227 | $image_sources = Helper::eael_get_woo_product_gallery_image_srcs( $product, $settings['eael_product_gallery_image_size_size'] ); |
| 228 | } |
| 229 | ?> |
| 230 | <div class="eael-product-wrap" data-src="<?php echo esc_url( $image_sources['src'] ); ?>" data-src-hover="<?php echo esc_url( $image_sources['src_hover'] ); ?>" > |
| 231 | <?php |
| 232 | do_action( 'eael_woocommerce_before_shop_loop_item' ); |
| 233 | if ( $settings['eael_wc_loop_hooks'] === 'yes' ) { |
| 234 | do_action( 'woocommerce_before_shop_loop_item' ); |
| 235 | } |
| 236 | ?> |
| 237 | <div class="product-image-wrap"> |
| 238 | <div class="image-wrap"> |
| 239 | <?php if( $should_print_image_clickable ) { |
| 240 | echo '<a href="' . $product->get_permalink() . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">'; |
| 241 | } |
| 242 | |
| 243 | echo( ! $product->is_in_stock() ? '<span class="eael-onsale outofstock ' . esc_attr( $sale_badge_preset . ' ' . $sale_badge_align ) . '">' . Helper::eael_wp_kses( $stockout_text ) . '</span>' : ( $product->is_on_sale() ? '<span class="eael-onsale ' . esc_attr( $sale_badge_preset . ' ' . $sale_badge_align ) . '">' . wp_kses( $sale_text, Helper::eael_allowed_tags() ) . '</span>' : '' ) ); |
| 244 | echo $product->get_image( $settings['eael_product_gallery_image_size_size'], ['loading' => 'eager', 'alt' => esc_attr( $product->get_title() )] ); |
| 245 | |
| 246 | if( $should_print_image_clickable ) { |
| 247 | echo '</a>'; |
| 248 | } ?> |
| 249 | </div> |
| 250 | <div class="image-hover-wrap"> |
| 251 | <ul class="icons-wrap over-box-style"> |
| 252 | <?php if( $should_print_addtocart ){?> |
| 253 | <li class="add-to-cart"><?php woocommerce_template_loop_add_to_cart(); ?></li> |
| 254 | <?php } ?> |
| 255 | <?php if( $should_print_quick_view ){?> |
| 256 | <li class="eael-product-quick-view"> |
| 257 | <a id="eael_quick_view_<?php echo uniqid(); ?>" data-quickview-setting="<?php echo htmlspecialchars(json_encode($quick_view_setting),ENT_QUOTES); ?>" |
| 258 | class="eael-product-gallery-open-popup open-popup-link"> |
| 259 | <i class="fas fa-eye"></i> |
| 260 | </a> |
| 261 | </li> |
| 262 | <?php } ?> |
| 263 | <?php if( $should_print_link ){?> |
| 264 | <li class="view-details"><?php echo '<a href="' . $product->get_permalink |
| 265 | () . '"><i class="fas fa-link"></i></a>'; ?></li> |
| 266 | <?php } ?> |
| 267 | </ul> |
| 268 | </div> |
| 269 | </div> |
| 270 | <div class="product-details-wrap"> |
| 271 | <?php |
| 272 | $_product_data = []; |
| 273 | $_product_data['price'] = $product_data['price']; |
| 274 | $_product_data['title'] = '<div class="eael-product-title"><a href="' . $product->get_permalink() . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">' . |
| 275 | $product_data['title'] . '</a></div>'; |
| 276 | |
| 277 | $product_data = apply_filters( 'eael/product-gallery/content/reordering', $_product_data, $settings, $product ); |
| 278 | if ( ! empty( $product_data ) ) { |
| 279 | foreach ( $product_data as $content ) { |
| 280 | if ( ! empty( $content ) ) { |
| 281 | echo wp_kses( $content, Helper::eael_allowed_tags(), Helper::eael_allowed_protocols() ); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | ?> |
| 286 | </div> |
| 287 | <?php |
| 288 | if ( $settings['eael_wc_loop_hooks'] === 'yes' ) { |
| 289 | do_action( 'woocommerce_after_shop_loop_item' ); |
| 290 | } |
| 291 | do_action( 'eael_woocommerce_after_shop_loop_item' ); |
| 292 | ?> |
| 293 | </div> |
| 294 | </li> |
| 295 | <?php |
| 296 | |
| 297 | } |
| 298 |