PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
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 / TPTQuantityMeasurementField.php

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

96 lines 3.2 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 // the description is plugin-defined text (settings arrays), read once for output
27 $description = (string) ( $value['desc'] ?? '' );
28 if ( ! isset( $value['id'] ) ) {
29 $value['id'] = '';
30 }
31
32 if ( ! isset( $value['title'] ) ) {
33 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
34 }
35
36 if ( ! isset( $value['default'] ) ) {
37 $value['default'] = array( 'singular' => '', 'plural' => '' );
38 }
39
40 if ( ! isset( $value['value'] ) ) {
41 $value['value'] = \WC_Admin_Settings::get_option( $value['id'], $value['default'] );
42 }
43
44 if ( ! isset( $value['desc'] ) ) {
45 $value['desc'] = '';
46 }
47
48 $value['value'] = isset( $value['value'] ) ? (array) $value['value'] : array();
49
50 $_value['singular'] = isset( $value['value']['singular'] ) ? sanitize_text_field( $value['value']['singular'] ) : '';
51 $_value['plural'] = isset( $value['value']['plural'] ) ? sanitize_text_field( $value['value']['plural'] ) : '';
52
53 ?>
54 <tr valign="top">
55 <th scope="row" class="titledesc">
56 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
57 </th>
58 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
59 <div>
60
61 <div style="display: flex; width: 400px; justify-content: space-between ">
62 <div>
63 <label for="<?php echo esc_attr( $value['id'] ); ?>-singular">
64 <?php esc_html_e( 'Singular', 'tier-pricing-table' ); ?>:
65 </label>
66 <br>
67 <input type="text" style="width: 190px;"
68 value="<?php echo esc_attr( $_value['singular'] ); ?>"
69 name="<?php echo esc_attr( $value['id'] ); ?>[singular]"
70 id="<?php echo esc_attr( $value['id'] ); ?>-singular"
71 placeholder="<?php esc_attr_e( 'e.g., piece', 'tier-pricing-table' ); ?>">
72 </div>
73
74 <div>
75 <label for="<?php echo esc_attr( $value['id'] ); ?>-plural">
76 <?php esc_html_e( 'Plural', 'tier-pricing-table' ); ?>:
77 </label>
78 <br>
79 <input type="text" style="width: 190px;"
80 value="<?php echo esc_attr( $_value['plural'] ); ?>"
81 name="<?php echo esc_attr( $value['id'] ); ?>[plural]"
82 id="<?php echo esc_attr( $value['id'] ); ?>-plural"
83 placeholder="<?php esc_attr_e( 'e.g., pieces', 'tier-pricing-table' ); ?>">
84 </div>
85 </div>
86 </div>
87 <p class="description">
88 <?php
89 echo wp_kses_post( $description ); // nosemgrep
90 ?>
91 </p>
92 </td>
93 </tr>
94 <?php
95 }
96 }