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 / TPTFeatureFlagOption.php

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

83 lines 2.4 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 TPTFeatureFlagOption {
4
5 const FIELD_TYPE = 'tpt_feature_flag_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 = in_array( $value, array( 1, 'yes' ) ) ? 'yes' : 'no';
14 }
15
16 return $value;
17 }, 10, 3 );
18 }
19
20 public function render( $value ) {
21 // the description is plugin-defined text (settings arrays), read once for output
22 $description = (string) ( $value['desc'] ?? '' );
23 if ( ! isset( $value['id'] ) ) {
24 $value['id'] = '';
25 }
26
27 if ( ! isset( $value['title'] ) ) {
28 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
29 }
30 if ( ! isset( $value['default'] ) ) {
31 $value['default'] = '';
32 }
33
34 if ( ! isset( $value['value'] ) ) {
35 $value['value'] = \WC_Admin_Settings::get_option( $value['id'], $value['default'] );
36 }
37
38 if ( ! isset( $value['on_label'] ) ) {
39 $value['on_label'] = __( 'On', 'role-and-customer-based-pricing-for-woocommerce' );
40 }
41
42 if ( ! isset( $value['off_label'] ) ) {
43 $value['off_label'] = __( 'Off', 'role-and-customer-based-pricing-for-woocommerce' );
44 }
45 if ( ! isset( $value['desc'] ) ) {
46 $value['desc'] = '';
47 }
48
49 $option_value = $value['value'];
50 ?>
51 <tr class="tpt-feature-flag-item">
52 <td>
53 <div class="tpt-feature-flag-wrapper">
54 <div class="tpt-feature-flag-item__description">
55 <h4><?php echo esc_html( $value['title'] ); ?></h4>
56
57 <p class="description">
58 <?php
59 echo wp_kses_post( $description ); // nosemgrep
60 ?>
61 </p>
62 <div class="tpt-feature-flag-item-checkbox">
63 <input
64 name="<?php echo esc_attr( $value['id'] ); ?>"
65 id="<?php echo esc_attr( $value['id'] ); ?>"
66 type="checkbox"
67 value="1"
68 <?php checked( $option_value, 'yes' ); ?>
69 class="tpt-toggle-switch"
70 />
71 <label for="<?php echo esc_attr( $value['id'] ); ?>">
72 <span data-tpt-toggle-switch-on><?php echo esc_attr( $value['on_label'] ); ?></span>
73 <span data-tpt-toggle-switch-off><?php echo esc_attr( $value['off_label'] ); ?></span>
74 </label>
75 </div>
76 </div>
77 </div>
78 </td>
79 </tr>
80 <?php
81 }
82 }
83