PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.1.0
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Settings / CustomOptions / TPTTextTemplate.php

TPTTextTemplate.php in Tiered Pricing Table for WooCommerce 6.1.0, at src/Settings/CustomOptions/TPTTextTemplate.php

213 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Settings\CustomOptions;
2
3 use TierPricingTable\Core\ServiceContainerTrait;
4
5 class TPTTextTemplate {
6
7 const FIELD_TYPE = 'tpt_text_template';
8
9 /**
10 * Editor id
11 *
12 * @var mixed|string
13 */
14 private $editorId;
15
16 use ServiceContainerTrait;
17
18 public function __construct() {
19 add_action( 'woocommerce_admin_field_' . self::FIELD_TYPE, array( $this, 'render' ) );
20
21 add_action( 'admin_head', function () {
22 ?>
23 <script>
24 var TPTAvailableCustomButtons = JSON.parse('<?php echo wp_kses_post( wp_json_encode( $this->getAvailableVariables() ) ); ?>');
25 </script>
26
27 <?php
28 } );
29
30 add_filter( 'mce_external_plugins', function ( $plugins, $editor ) {
31 if ( $this->editorId === $editor ) {
32 $plugins['tiered-pricing-custom-mce-buttons'] = $this->getContainer()->getFileManager()->locateJSAsset( 'admin/mce' );
33 }
34
35 return $plugins;
36 }, 10, 2 );
37
38 add_filter( 'mce_buttons', function ( $buttons ) {
39
40 $buttons = array_merge( $buttons, array_keys( $this->getAvailableVariables() ) );
41
42 return $buttons;
43 } );
44
45 add_action( 'woocommerce_admin_settings_sanitize_option', function ( $value, $option, $rawValue ) {
46
47 if ( self::FIELD_TYPE === $option['type'] ) {
48 return wp_kses_post( $rawValue );
49 }
50
51 return $value;
52 }, 10, 3 );
53
54 }
55
56 public function render( $value ) {
57 if ( ! isset( $value['id'] ) ) {
58 $value['id'] = '';
59 }
60 if ( ! isset( $value['title'] ) ) {
61 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
62 }
63 if ( ! isset( $value['default'] ) ) {
64 $value['default'] = '';
65 }
66 if ( ! isset( $value['desc'] ) ) {
67 $value['desc'] = '';
68 }
69 if ( ! isset( $value['desc_tip'] ) ) {
70 $value['desc_tip'] = false;
71 }
72 if ( ! isset( $value['placeholder'] ) ) {
73 $value['placeholder'] = '';
74 }
75 if ( ! isset( $value['value'] ) ) {
76 $value['value'] = \WC_Admin_Settings::get_option( $value['id'], $value['default'] );
77 }
78
79 $option_value = $value['value'];
80
81 $this->editorId = $value['id'];
82
83 $value['placeholders'] = is_array( $value['placeholders'] ) ? $value['placeholders'] : array();
84 ?>
85 <style>
86 #wp-<?php echo esc_html($value['id']); ?>-wrap .wp-editor-tools {
87 display: none;
88 }
89
90 #wp-<?php echo esc_html($value['id']); ?>-wrap {
91 max-width: 500px;
92 }
93 </style>
94 <tr valign="top">
95 <th scope="row" class="titledesc">
96 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
97 </th>
98 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
99 <?php
100 wp_editor( $option_value, $value['id'], array(
101 'wpautop' => true,
102 'media_buttons' => false,
103
104 'textarea_name' => $value['id'],
105 'editor_height' => 30,
106 'tabindex' => null,
107 'editor_class' => 'tpt-message-template-mce',
108 'tinymce' => array(
109 'resize' => 'vertical',
110 'menubar' => false,
111 'wpautop' => true,
112 'toolbar2' => '',
113 'toolbar1' => implode( ',', array_merge( array(
114 'bold',
115 'italic',
116 'strikethrough',
117 'link',
118
119 'spellchecker',
120 ), $value['placeholders'] ) ),
121 ),
122 'quicktags' => array(
123 'id' => $value['id'],
124 'buttons' => 'strong,em,del',
125 ),
126 'drag_drop_upload' => false,
127 ) );
128 ?>
129
130 <?php if ( $value['desc'] ) : ?>
131 <p class="description"><?php echo wp_kses_post( $value['desc'] ); ?></p>
132 <?php endif; ?>
133 </td>
134 </tr>
135 <?php
136 }
137
138 protected function getAvailableVariables() {
139 return array(
140 'tp_quantity' => array(
141 'name' => __( 'Quantity', 'tier-pricing-table' ),
142 'description' => __( '{tp_quantity} - range or a static quantity of the current pricing tier.',
143 'tier-pricing-table' ),
144 'variableKey' => '{tp_quantity}',
145 ),
146
147 'tp_discount' => array(
148 'name' => __( 'Percentage discount', 'tier-pricing-table' ),
149 'description' => __( '{tp_discount} - current tier`s percentage discount.', 'tier-pricing-table' ),
150 'variableKey' => '{tp_discount}',
151 ),
152
153 'tp_rounded_discount' => array(
154 'name' => __( 'Rounded percentage discount', 'tier-pricing-table' ),
155 'description' => __( '{tp_rounded_discount} - current tier`s rounded percentage discount.',
156 'tier-pricing-table' ),
157 'variableKey' => '{tp_rounded_discount}',
158 ),
159
160 'tp_required_quantity' => array(
161 'name' => __( 'Required quantity', 'tier-pricing-table' ),
162 'description' => __( '{tp_required_quantity} - required quantity to add a next tiered pricing.',
163 'tier-pricing-table' ),
164 'variableKey' => '{tp_required_quantity}',
165 ),
166
167 'tp_next_price' => array(
168 'name' => __( 'Next price', 'tier-pricing-table' ),
169 'description' => __( '{tp_next_price} - next tiered pricing price user can get if they add required quantity.',
170 'tier-pricing-table' ),
171 'variableKey' => '{tp_next_price}',
172 ),
173
174 'tp_next_discount' => array(
175 'name' => __( 'Next discount', 'tier-pricing-table' ),
176 'description' => __( '{tp_next_discount} - next discount if they add required quantity.',
177 'tier-pricing-table' ),
178 'variableKey' => '{tp_next_discount}',
179 ),
180
181 'tp_actual_discount' => array(
182 'name' => __( 'Next actual discount', 'tier-pricing-table' ),
183 'description' => __( '{tp_actual_discount} - discount based on the original product price.',
184 'tier-pricing-table' ),
185 'variableKey' => '{tp_actual_discount}',
186 ),
187 'tp_ys_price' => array(
188 'name' => __( 'Save price', 'tier-pricing-table' ),
189 'description' => __( '{tp_ys_price} - difference between regular and current price.',
190 'tier-pricing-table' ),
191 'variableKey' => '{tp_ys_price}',
192 ),
193 'tp_ys_total_price' => array(
194 'name' => __( 'Total save price', 'tier-pricing-table' ),
195 'description' => __( '{tp_ys_total_price} - difference between regular and current price multiplied by quantity.',
196 'tier-pricing-table' ),
197 'variableKey' => '{tp_ys_total_price}',
198 ),
199 'tp_price' => array(
200 'name' => __( 'Price', 'tier-pricing-table' ),
201 'description' => __( '{tp_price} - Tier price for one piece', 'tier-pricing-table' ),
202 'variableKey' => '{tp_price}',
203 ),
204 'tp_base_unit_name' => array(
205 'name' => __( 'Unit label', 'tier-pricing-table' ),
206 'description' => __( 'It will use Unit label from products if you set it.', 'tier-pricing-table' ),
207 'variableKey' => '{tp_base_unit_name}',
208 ),
209
210 );
211 }
212 }
213