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

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

89 lines 2.8 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 TPTSwitchOption {
4
5 const FIELD_TYPE = 'tpt_switch_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 $extendedDescription = (string) ( $value['extended_description'] ?? '' );
24 if ( ! isset( $value['id'] ) ) {
25 $value['id'] = '';
26 }
27
28 if ( ! isset( $value['custom_attributes'] ) ) {
29 $value['custom_attributes'] = array();
30 } else {
31 $value['custom_attributes'] = array_keys( $value['custom_attributes'] );
32 }
33
34 if ( ! isset( $value['title'] ) ) {
35 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
36 }
37 if ( ! isset( $value['default'] ) ) {
38 $value['default'] = '';
39 }
40
41 if ( ! isset( $value['value'] ) ) {
42 $value['value'] = \WC_Admin_Settings::get_option( $value['id'], $value['default'] );
43 }
44
45 if ( ! isset( $value['on_label'] ) ) {
46 $value['on_label'] = __( 'On', 'role-and-customer-based-pricing-for-woocommerce' );
47 }
48
49 if ( ! isset( $value['off_label'] ) ) {
50 $value['off_label'] = __( 'Off', 'role-and-customer-based-pricing-for-woocommerce' );
51 }
52 if ( ! isset( $value['desc'] ) ) {
53 $value['desc'] = '';
54 }
55
56 $option_value = $value['value'];
57
58 ?>
59 <tr valign="top">
60 <th scope="row" class="titledesc">
61 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
62 </th>
63 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
64 <div>
65 <input
66 <?php echo esc_attr(implode( ' ', $value['custom_attributes'] )); ?>
67 name="<?php echo esc_attr( $value['id'] ); ?>"
68 id="<?php echo esc_attr( $value['id'] ); ?>"
69 type="checkbox"
70 value="1"
71 <?php checked( $option_value, 'yes' ); ?>
72 class="tpt-toggle-switch"
73 />
74 <label for="<?php echo esc_attr( $value['id'] ); ?>">
75 <span data-tpt-toggle-switch-on><?php echo esc_attr( $value['on_label'] ); ?></span>
76 <span data-tpt-toggle-switch-off><?php echo esc_attr( $value['off_label'] ); ?></span>
77 </label>
78 </div>
79 <p class="description"><?php echo wp_kses_post( $description ); // nosemgrep ?></p>
80 <?php if ( isset( $value['extended_description'] ) ) : ?>
81 <div class="tpt-toggle-extended-description">
82 <?php echo wp_kses_post( $extendedDescription ); // nosemgrep ?>
83 </div>
84 <?php endif; ?>
85 </td>
86 </tr>
87 <?php
88 }
89 }