default.php
190 lines
| 1 | <?php |
| 2 | defined('ABSPATH') || exit; |
| 3 | $args = array( |
| 4 | 'post_type' => ['product', 'product_variation'], |
| 5 | 'status' => 'publish', |
| 6 | 'meta_query' => array( |
| 7 | array( |
| 8 | 'key' => '_sale_price_dates_to', |
| 9 | 'value' => time(), |
| 10 | 'compare' => '>' |
| 11 | ), |
| 12 | array( |
| 13 | 'key' => '_sale_price', |
| 14 | 'value' => 0, |
| 15 | 'compare' => '>' |
| 16 | ), |
| 17 | ), |
| 18 | 'posts_per_page' => isset($settings['products_per_page']) ? $settings['products_per_page'] : 4, |
| 19 | 'order' => isset($settings['product_order']) ? $settings['product_order'] : 'DESC', |
| 20 | 'orderby' => isset($settings['product_orderby']) ? $settings['product_orderby'] : 'date', |
| 21 | ); |
| 22 | |
| 23 | $query = new WP_Query($args); |
| 24 | $post_type = get_post_type(); |
| 25 | |
| 26 | ?> |
| 27 | |
| 28 | <div class="shopengine-widget"> |
| 29 | <div class="shopengine-deal-products-widget"> |
| 30 | <div class="deal-products-container"> |
| 31 | <?php |
| 32 | |
| 33 | if($query->have_posts()): while($query->have_posts()): $query->the_post(); |
| 34 | |
| 35 | $id = get_the_ID(); |
| 36 | $title = wp_trim_words( get_the_title(), $settings['title_word_limit'] , '...' ); |
| 37 | $image_id = get_post_thumbnail_id($id); |
| 38 | $product = wc_get_product( $id ); |
| 39 | |
| 40 | $price = wc_price( $product->get_price() ); |
| 41 | $reg_price = wc_price( $product->get_regular_price() ); |
| 42 | $stock_qty = $product->get_stock_quantity(); |
| 43 | $total_sell = $product->get_total_sales(); |
| 44 | $available = $stock_qty ; |
| 45 | $offPercentage = 100 ; |
| 46 | if( $product->get_regular_price() > 0 ) { |
| 47 | $offPercentage = $product->get_price() / $product->get_regular_price() * 100; |
| 48 | } |
| 49 | |
| 50 | $sales_price_from = get_post_meta( $id, '_sale_price_dates_from', true ); |
| 51 | $sales_price_to = get_post_meta( $id, '_sale_price_dates_to', true ); |
| 52 | $current_time = strtotime(date('Y-m-d H:i:s')); // get the current time |
| 53 | $is_time_over = ($sales_price_to - $current_time) < 0 ? true : false; |
| 54 | |
| 55 | // when time is over, hide the deal product form the list |
| 56 | if ( $is_time_over ) continue; |
| 57 | |
| 58 | // when woo commerce date form value not found it will take the date when the post was created |
| 59 | if( !isset( $sales_price_from ) || empty( $sales_price_from ) ){ |
| 60 | $sales_price_from = strtotime(get_the_date()); |
| 61 | } |
| 62 | |
| 63 | // data for countdown clock |
| 64 | $deal_data = [ |
| 65 | 'start_time' => date('Y-m-d H:i:s',$sales_price_from), |
| 66 | 'end_time' => date('Y-m-d H:i:s',$sales_price_to), |
| 67 | 'show_days' => ( $settings['shopengine_show_countdown_clock_days'] === 'yes' ) ? 'yes' : 'no' , |
| 68 | ]; |
| 69 | |
| 70 | |
| 71 | // options for sell and available section |
| 72 | $progress_data = [ |
| 73 | 'bg_line_clr' => (isset($settings['shopengine_product_stock_bg_line_clr'])) ? $settings['shopengine_product_stock_bg_line_clr'] : '#F2F2F2', |
| 74 | 'bg_line_height' => (isset($settings['shopengine_product_stock_bg_line_height']['size'])) ? $settings['shopengine_product_stock_bg_line_height']['size'] : 2, |
| 75 | 'bg_line_cap' => (isset($settings['shopengine_product_stock_line_cap'])) ? $settings['shopengine_product_stock_line_cap'] : 'round', // "butt|round|square" |
| 76 | |
| 77 | 'prog_line_clr' => (isset($settings['shopengine_product_stock_prog_line_clr'])) ? $settings['shopengine_product_stock_prog_line_clr'] : '#F03D3F', |
| 78 | 'prog_line_height'=> (isset($settings['shopengine_product_stock_prog_line_height']['size'])) ? $settings['shopengine_product_stock_prog_line_height']['size'] : 4, |
| 79 | 'prog_line_cap' => (isset($settings['shopengine_product_stock_line_cap'])) ? $settings['shopengine_product_stock_line_cap'] : 'round', |
| 80 | |
| 81 | 'stock_qty' => $stock_qty, |
| 82 | 'total_sell' => $total_sell |
| 83 | ]; |
| 84 | |
| 85 | ?> |
| 86 | |
| 87 | <div class="deal-products" data-deal-data='<?php echo json_encode($deal_data) ?>'> |
| 88 | |
| 89 | <div class="deal-products__top"> |
| 90 | <!-- product image --> |
| 91 | <?php echo wp_get_attachment_image( $image_id, "", false, ['class' => 'deal-products__top--img'] ); ?> |
| 92 | <!-- offer show in percentage --> |
| 93 | <?php if($settings['shopengine_show_percentage_badge'] === 'yes' && $product->get_regular_price() !== 0): ?> |
| 94 | <span class="shopengine-offer-badge"> -<?php echo esc_html( 100 - round($offPercentage,2) ); ?>%</span> |
| 95 | <?php endif; ?> |
| 96 | |
| 97 | <!-- sale badge --> |
| 98 | <?php if($settings['shopengine_is_sale_badge'] === 'yes' ): ?> |
| 99 | <span class="shopengine-sale-badge"> <?php echo esc_html($settings['shopengine_sale_badge_text']); ?> </span> |
| 100 | <?php endif; ?> |
| 101 | |
| 102 | <!-- countdown clock --> |
| 103 | <?php if( $settings['shopengine_show_countdown_clock'] === 'yes' ): ?> |
| 104 | <div class="shopengine-countdown-clock"> |
| 105 | |
| 106 | <?php if( $settings['shopengine_show_countdown_clock_days'] === 'yes' ): ?> |
| 107 | <span class="se-clock-item"> |
| 108 | <span class="clock-days"></span> |
| 109 | <span class="clock-days-label"><?php echo esc_html__('Days', 'shopengine') ?></span> |
| 110 | </span> |
| 111 | <?php endif; ?> |
| 112 | |
| 113 | <span class="se-clock-item"> |
| 114 | <span class="clock-hou"></span> |
| 115 | <span class="clock-hou-label"><?php echo esc_html__('Hours', 'shopengine') ?></span> |
| 116 | </span> |
| 117 | |
| 118 | <span class="se-clock-item"> |
| 119 | <span class="clock-min"></span> |
| 120 | <span class="clock-min-label"><?php echo esc_html__('Min', 'shopengine') ?></span> |
| 121 | </span> |
| 122 | |
| 123 | <span class="se-clock-item"> |
| 124 | <span class="clock-sec"></span> |
| 125 | <span class="clock-sec-label"><?php echo esc_html__('Sec', 'shopengine') ?></span> |
| 126 | </span> |
| 127 | </div> |
| 128 | |
| 129 | <?php endif; ?> |
| 130 | |
| 131 | </div> |
| 132 | |
| 133 | <!-- product description --> |
| 134 | <div class="deal-products__desc"> |
| 135 | <h4 class="deal-products__desc--name"> <a title="<?php esc_html_e('Dealing Product','shopengine')?>" href="<?php the_permalink() ?>"> <?php echo esc_html($title) ?> </a> </h4> |
| 136 | </div> |
| 137 | |
| 138 | <!-- product description --> |
| 139 | <div class="deal-products__prices"> |
| 140 | <ins><span class="woocommerce-Price-amount amount"><?php echo wp_kses($price, \Shopengine\Utils\Helper::get_kses_array()) ?> </span></ins> |
| 141 | |
| 142 | <?php if( !empty( $price ) ) : ?> |
| 143 | <del> |
| 144 | <span class="woocommerce-Price-amount amount"> |
| 145 | <?php echo wp_kses($reg_price, \Shopengine\Utils\Helper::get_kses_array()) ?> |
| 146 | </span> |
| 147 | </del> |
| 148 | <?php endif; ?> |
| 149 | |
| 150 | </div> |
| 151 | |
| 152 | <?php |
| 153 | if($settings['shopengine_deal_product_show_cart_btn'] == 'yes'): ?> |
| 154 | <div class="add-to-cart-bt"> |
| 155 | <?php woocommerce_template_loop_add_to_cart(); ?> |
| 156 | </div> |
| 157 | |
| 158 | <?php endif; ?> |
| 159 | |
| 160 | <!-- stock and sold line chart --> |
| 161 | <?php if($settings['shopengine_show_sold_chart'] === 'yes'): ?> |
| 162 | <div class="deal-products__grap"> |
| 163 | <canvas class="deal-products__grap--line" height="<?php echo esc_attr($progress_data['prog_line_height'] + 2) ?>" data-settings='<?php echo json_encode($progress_data) ?>'></canvas> |
| 164 | <div class="deal-products__grap__sells"> |
| 165 | <div class="deal-products__grap--available"> |
| 166 | <span><?php echo esc_html__('Available:', 'shopengine') ?></span> |
| 167 | <span class="avl_num"><?php echo esc_html( $available ) ?></span> |
| 168 | </div> |
| 169 | <div class="deal-products__grap--sold"> |
| 170 | <span><?php echo esc_html__( 'Sold:', 'shopengine' ) ?></span> |
| 171 | <span class="sld_num"><?php echo esc_html( $total_sell ) ?></span> |
| 172 | </div> |
| 173 | </div> |
| 174 | </div> |
| 175 | <?php endif;?> |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | </div> |
| 181 | |
| 182 | |
| 183 | <?php |
| 184 | |
| 185 | endwhile; elseif( $post_type == \ShopEngine\Core\Template_Cpt::TYPE ): |
| 186 | echo esc_html__('No deal products available', 'shopengine'); |
| 187 | endif; wp_reset_postdata(); ?> |
| 188 | </div> |
| 189 | </div> |
| 190 | </div> |