PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / templates / modules / volume-discounts / admin-preview.php

admin-preview.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.2, at templates/modules/volume-discounts/admin-preview.php

179 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Template for Bulk Discounts Single Product
5 *
6 * @var array $args template args
7 *
8 * @since 1.4
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14 ?>
15 <div class="standard-style">
16 <div class="merchant-volume-discounts">
17 <?php
18 $in_cart = 'false';
19 $quantity = 0;
20 if ( ! empty( $args['in_cart'] ) ) {
21 $in_cart = 'true';
22 }
23 if ( ! empty( $args['product_cart_quantity'] ) ) {
24 $quantity = $args['product_cart_quantity'];
25 }
26 foreach ( $args['discount_tiers'] as $discount_tier ) :
27 if ( isset( $discount_tier['discount_type'], $discount_tier['product_single_page']['save_label'], $discount_tier['product_single_page']['item_text'], $discount_tier['product_single_page']['total_text'] ) ) {
28 $discount = $discount_tier['discount_type'] === 'percentage_discount'
29 ? ( $args['product_price'] * $discount_tier['discount'] ) / 100
30 : $discount_tier['discount'];
31
32 $discount_percent = ( $discount_tier['discount'] ?? 0 ) . '%';
33 $discount_qty = (int) ( $discount_tier['quantity'] ?? 1 );
34
35 $discounted_price = $args['product_price'] - $discount;
36 $total_discount = intval( $discount_qty ) * $discount;
37 $total_price = intval( $discount_qty ) * $discounted_price;
38 $clickable = '';
39 $product_id = $args['product_id'] ?? get_the_ID();
40 $product_type = '';
41
42 if ( $product_id ) {
43 $product = wc_get_product( $product_id );
44 $product_type = $product->get_type();
45 if ( $product && ! $product->is_type( 'variable' ) && $quantity < $discount_qty ) {
46 $clickable = ' clickable';
47 }
48 }
49
50 if ( isset( $discount_tier['product_single_page']['table_title'] ) && ! empty( $discount_tier['product_single_page']['table_title'] ) ) : ?>
51 <div class="merchant-volume-discounts-title" style="<?php
52 echo isset( $discount_tier['product_single_page']['title_font_weight'] ) ? esc_attr( 'font-weight: ' . $discount_tier['product_single_page']['title_font_weight'] . ';' ) : '';
53 echo isset( $discount_tier['product_single_page']['title_font_size'] ) ? esc_attr( 'font-size: ' . $discount_tier['product_single_page']['title_font_size'] . 'px;' ) : '';
54 echo isset( $discount_tier['product_single_page']['title_text_color'] ) ? esc_attr( 'color: ' . $discount_tier['product_single_page']['title_text_color'] . ';' ) : ''; ?>"><?php
55 echo esc_html( Merchant_Translator::translate( $discount_tier['product_single_page']['table_title'] ) ); ?>
56 </div>
57 <?php
58 endif;
59
60 $item_classes = 'merchant-volume-discounts-item' . esc_attr( $clickable );
61 $item_classes .= $product_type ? ' merchant-volume-discounts-item-' . esc_attr( $product_type ) : '';
62 ?>
63 <div class="<?php echo esc_attr( $item_classes ); ?>" title="<?php echo esc_attr__( 'Add offer to cart', 'merchant' ); ?>" data-in-cart="<?php
64 echo esc_attr( $in_cart ); ?>" data-product-id="<?php echo esc_attr( $product_id ); ?>" data-offer-quantity="<?php echo esc_attr( $discount_qty ); ?>" style="<?php
65 echo isset( $discount_tier['product_single_page']['table_item_bg_color'] ) ? esc_attr( 'background-color: ' . $discount_tier['product_single_page']['table_item_bg_color'] . ';' ) : '';
66 echo isset( $discount_tier['product_single_page']['table_item_border_color'] ) ? esc_attr( 'border-color: ' . $discount_tier['product_single_page']['table_item_border_color'] . ';' ) : '';
67 echo isset( $discount_tier['product_single_page']['table_item_text_color'] ) ? esc_attr( 'color: ' . $discount_tier['product_single_page']['table_item_text_color'] . ';' ) : ''; ?>">
68 <div class="merchant-volume-discounts-buy-label">
69 <span class="inner-text">
70 <?php
71 /**
72 * Previously wrong variable `{amount}` was used for this field. Correct one should be `{quantity}`.
73 * Still keeping the wrong one `{amount}` for backward compatibility.
74 */
75 if ( isset( $discount_tier['product_single_page']['buy_text'] ) ) {
76 echo wp_kses(
77 str_replace(
78 array(
79 '{amount}',
80 '{quantity}',
81 '{discount}',
82 '{percent}',
83 ),
84 array(
85 '<strong>' . esc_html( $discount_qty ) . '</strong>',
86 '<strong>' . esc_html( $discount_qty ) . '</strong>',
87 '<strong>' . wc_price( $discount ) . '</strong>',
88 '<strong>' . esc_html( $discount_percent ) . '</strong>',
89 ),
90 esc_html( Merchant_Translator::translate( $discount_tier['product_single_page']['buy_text'] ) )
91 ),
92 merchant_kses_allowed_tags( array( 'bdi' ) )
93 );
94 } else {
95 echo wp_kses(
96 str_replace(
97 array(
98 '{quantity}',
99 '{discount}',
100 ),
101 array(
102 '<strong>' . esc_html( $discount_qty ) . '</strong>',
103 '<strong>' . wc_price( $discount ) . '</strong>',
104 ),
105 esc_html__( 'Buy {quantity}, get {discount} off each', 'merchant' )
106 ),
107 merchant_kses_allowed_tags( array( 'bdi' ) )
108 );
109 }
110 ?>
111 </span>
112 </div>
113 <ul>
114 <li>
115 <div></div>
116 <div>
117 <del><?php
118 echo wp_kses( wc_price( $args['product_price'] ), merchant_kses_allowed_tags( array( 'bdi' ) ) ); ?></del>
119 </div>
120 </li>
121 <li>
122 <div class="merchant-volume-discounts-item-text"><?php
123 echo isset($discount_tier['product_single_page']['item_text']) ? esc_html( Merchant_Translator::translate( $discount_tier['product_single_page']['item_text'] ) ) : esc_html__( 'Per item:', 'merchant' ); ?></div>
124 <div><strong><?php
125 echo wp_kses( wc_price( $discounted_price ), merchant_kses_allowed_tags( array( 'bdi' ) ) ); ?></strong></div>
126 </li>
127 <li>
128 <div class="merchant-volume-discounts-total-text"><?php
129 echo isset( $discount_tier['product_single_page']['total_text'] )
130 ? esc_html( Merchant_Translator::translate( $discount_tier['product_single_page']['total_text'] ) )
131 : esc_html__( 'Total price:', 'merchant' ); ?></div>
132 <div><strong><?php
133 echo wp_kses( wc_price( $total_price ), merchant_kses_allowed_tags( array( 'bdi' ) ) ); ?></strong></div>
134 </li>
135 </ul>
136 <div class="merchant-volume-discounts-item-label">
137 <span class="merchant-volume-discounts-save-label" style="<?php
138 echo isset( $discount_tier['product_single_page']['table_label_bg_color'] ) ? esc_attr( 'background-color: ' . $discount_tier['product_single_page']['table_label_bg_color'] . ';' ) : '';
139 echo isset( $discount_tier['product_single_page']['table_label_text_color'] ) ? esc_attr( 'color: ' . $discount_tier['product_single_page']['table_label_text_color'] . ';' ) : ''; ?>">
140 <?php
141 if ( isset( $discount_tier['product_single_page']['save_label'] ) ) {
142 echo wp_kses(
143 str_replace(
144 array(
145 '{amount}',
146 '{percent}',
147 ),
148 array(
149 wc_price( $total_discount ),
150 esc_html( $discount_percent ),
151 ),
152 esc_html( Merchant_Translator::translate( $discount_tier['product_single_page']['save_label'] ) )
153 ),
154 merchant_kses_allowed_tags( array( 'bdi' ) )
155 );
156 } else {
157 echo wp_kses(
158 str_replace(
159 array(
160 '{amount}',
161 '{percent}',
162 ),
163 array(
164 wc_price( $total_discount ),
165 esc_html( $discount_percent ),
166 ),
167 esc_html__( 'Save {amount}', 'merchant' )
168 ),
169 merchant_kses_allowed_tags( array( 'bdi' ) )
170 );
171 } ?>
172 </span>
173 </div>
174 </div>
175 <?php
176 }
177 endforeach; ?>
178 </div>
179 </div>