PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.4
Tiered Pricing Table for WooCommerce v7.1.4
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 7.1.4, at src/Settings/CustomOptions/TPTFeatureFlagOption.php

81 lines 2.3 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 if ( ! isset( $value['id'] ) ) {
22 $value['id'] = '';
23 }
24
25 if ( ! isset( $value['title'] ) ) {
26 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
27 }
28 if ( ! isset( $value['default'] ) ) {
29 $value['default'] = '';
30 }
31
32 if ( ! isset( $value['value'] ) ) {
33 $value['value'] = \WC_Admin_Settings::get_option( $value['id'], $value['default'] );
34 }
35
36 if ( ! isset( $value['on_label'] ) ) {
37 $value['on_label'] = __( 'On', 'role-and-customer-based-pricing-for-woocommerce' );
38 }
39
40 if ( ! isset( $value['off_label'] ) ) {
41 $value['off_label'] = __( 'Off', 'role-and-customer-based-pricing-for-woocommerce' );
42 }
43 if ( ! isset( $value['desc'] ) ) {
44 $value['desc'] = '';
45 }
46
47 $option_value = $value['value'];
48 ?>
49 <tr class="tpt-feature-flag-item">
50 <td>
51 <div class="tpt-feature-flag-wrapper">
52 <div class="tpt-feature-flag-item__description">
53 <h4><?php echo esc_html( $value['title'] ); ?></h4>
54
55 <p class="description">
56 <?php
57 echo wp_kses_post( $value['desc'] ); // audit.php.wp.security.xss.shortcode-attr ignore
58 ?>
59 </p>
60 <div class="tpt-feature-flag-item-checkbox">
61 <input
62 name="<?php echo esc_attr( $value['id'] ); ?>"
63 id="<?php echo esc_attr( $value['id'] ); ?>"
64 type="checkbox"
65 value="1"
66 <?php checked( $option_value, 'yes' ); ?>
67 class="tpt-toggle-switch"
68 />
69 <label for="<?php echo esc_attr( $value['id'] ); ?>">
70 <span data-tpt-toggle-switch-on><?php echo esc_attr( $value['on_label'] ); ?></span>
71 <span data-tpt-toggle-switch-off><?php echo esc_attr( $value['off_label'] ); ?></span>
72 </label>
73 </div>
74 </div>
75 </div>
76 </td>
77 </tr>
78 <?php
79 }
80 }
81