PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.3
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.3
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 1.10.3, at templates/modules/volume-discounts/admin-preview.php

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