PluginProbe
Tiered Pricing Table for WooCommerce / trunk
Tiered Pricing Table for WooCommerce vtrunk
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 2.3.4 All 90 releases
tier-pricing-table / src / Settings / CustomOptions / TPTQuantityMeasurementField.php

TPTQuantityMeasurementField.php in Tiered Pricing Table for WooCommerce trunk, at src/Settings/CustomOptions/TPTQuantityMeasurementField.php

94 lines 3.1 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 class TPTQuantityMeasurementField {
4
5 const FIELD_TYPE = 'tpt_quantity_measurement_option';
6
7 public function __construct() {
8 add_action( 'woocommerce_admin_field_' . self::FIELD_TYPE, array( $this, 'render' ) );
9
10 add_action( 'woocommerce_admin_settings_sanitize_option', function ( $value, $option, $rawValue ) {
11
12 if ( self::FIELD_TYPE === $option['type'] ) {
13 $value = is_array( $value ) ? $value : array();
14
15 $_value['singular'] = isset( $value['singular'] ) ? sanitize_text_field( $value['singular'] ) : '';
16 $_value['plural'] = isset( $value['plural'] ) ? sanitize_text_field( $value['plural'] ) : '';
17
18 $value = $_value;
19 }
20
21 return $value;
22 }, 10, 3 );
23 }
24
25 public function render( $value ) {
26 if ( ! isset( $value['id'] ) ) {
27 $value['id'] = '';
28 }
29
30 if ( ! isset( $value['title'] ) ) {
31 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
32 }
33
34 if ( ! isset( $value['default'] ) ) {
35 $value['default'] = array( 'singular' => '', 'plural' => '' );
36 }
37
38 if ( ! isset( $value['value'] ) ) {
39 $value['value'] = \WC_Admin_Settings::get_option( $value['id'], $value['default'] );
40 }
41
42 if ( ! isset( $value['desc'] ) ) {
43 $value['desc'] = '';
44 }
45
46 $value['value'] = isset( $value['value'] ) ? (array) $value['value'] : array();
47
48 $_value['singular'] = isset( $value['value']['singular'] ) ? sanitize_text_field( $value['value']['singular'] ) : '';
49 $_value['plural'] = isset( $value['value']['plural'] ) ? sanitize_text_field( $value['value']['plural'] ) : '';
50
51 ?>
52 <tr valign="top">
53 <th scope="row" class="titledesc">
54 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
55 </th>
56 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
57 <div>
58
59 <div style="display: flex; width: 400px; justify-content: space-between ">
60 <div>
61 <label for="<?php echo esc_attr( $value['id'] ); ?>-singular">
62 <?php esc_html_e( 'Singular', 'tier-pricing-table' ); ?>:
63 </label>
64 <br>
65 <input type="text" style="width: 190px;"
66 value="<?php echo esc_attr( $_value['singular'] ); ?>"
67 name="<?php echo esc_attr( $value['id'] ); ?>[singular]"
68 id="<?php echo esc_attr( $value['id'] ); ?>-singular"
69 placeholder="<?php esc_attr_e( 'e.g., piece', 'tier-pricing-table' ); ?>">
70 </div>
71
72 <div>
73 <label for="<?php echo esc_attr( $value['id'] ); ?>-plural">
74 <?php esc_html_e( 'Plural', 'tier-pricing-table' ); ?>:
75 </label>
76 <br>
77 <input type="text" style="width: 190px;"
78 value="<?php echo esc_attr( $_value['plural'] ); ?>"
79 name="<?php echo esc_attr( $value['id'] ); ?>[plural]"
80 id="<?php echo esc_attr( $value['id'] ); ?>-plural"
81 placeholder="<?php esc_attr_e( 'e.g., pieces', 'tier-pricing-table' ); ?>">
82 </div>
83 </div>
84 </div>
85 <p class="description">
86 <?php
87 echo wp_kses_post( $value['desc'] ); // audit.php.wp.security.xss.shortcode-attr ignore
88 ?>
89 </p>
90 </td>
91 </tr>
92 <?php
93 }
94 }