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

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

87 lines 2.6 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 if ( ! isset( $value['id'] ) ) {
22 $value['id'] = '';
23 }
24
25 if ( ! isset( $value['custom_attributes'] ) ) {
26 $value['custom_attributes'] = array();
27 } else {
28 $value['custom_attributes'] = array_keys( $value['custom_attributes'] );
29 }
30
31 if ( ! isset( $value['title'] ) ) {
32 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
33 }
34 if ( ! isset( $value['default'] ) ) {
35 $value['default'] = '';
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['on_label'] ) ) {
43 $value['on_label'] = __( 'On', 'role-and-customer-based-pricing-for-woocommerce' );
44 }
45
46 if ( ! isset( $value['off_label'] ) ) {
47 $value['off_label'] = __( 'Off', 'role-and-customer-based-pricing-for-woocommerce' );
48 }
49 if ( ! isset( $value['desc'] ) ) {
50 $value['desc'] = '';
51 }
52
53 $option_value = $value['value'];
54
55 ?>
56 <tr valign="top">
57 <th scope="row" class="titledesc">
58 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
59 </th>
60 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
61 <div>
62 <input
63 <?php echo esc_attr(implode( ' ', $value['custom_attributes'] )); ?>
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 <p class="description"><?php echo wp_kses_post( $value['desc'] ); ?></p>
77
78 <?php if ( isset( $value['extended_description'] ) ) : ?>
79 <div class="tpt-toggle-extended-description">
80 <?php echo wp_kses_post( $value['extended_description'] ); ?>
81 </div>
82 <?php endif; ?>
83 </td>
84 </tr>
85 <?php
86 }
87 }