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

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

125 lines 4.5 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 TPTIntegrationOption {
4
5 const FIELD_TYPE = 'tpt_integration_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 $is_official = ! empty( $value['official'] );
51 $action_links = isset( $value['action_links'] ) && is_array( $value['action_links'] ) ? $value['action_links'] : array();
52 $meta_pills = isset( $value['meta_pills'] ) && is_array( $value['meta_pills'] ) ? $value['meta_pills'] : array();
53 ?>
54 <tr class="tpt-integration-item <?php echo $is_official ? 'tpt-integration-item--official' : ''; ?>">
55 <td>
56 <div class="tpt-integration-wrapper <?php echo $is_official ? 'tpt-integration-wrapper--official' : ''; ?>">
57 <div class="tpt-integration-item__image">
58 <img src="<?php echo esc_attr( $value['icon_url'] ); ?>"
59 alt="<?php echo esc_attr( $value['title'] ); ?>">
60 </div>
61 <div class="tpt-integration-item__description">
62 <div class="tpt-integration-item__content">
63
64 <?php $official_badge = $is_official ? ' <span class="tpt-integration-item__official-badge">' . esc_html__( 'By U2Code', 'tier-pricing-table' ) . '</span>' : ''; ?>
65 <?php if ( $value['author_url'] ) : ?>
66 <a target="_blank" href="<?php echo esc_attr( $value['author_url'] ); ?>">
67 <h4><?php echo esc_html( $value['title'] ) . wp_kses_post( $official_badge ); ?></h4>
68 </a>
69 <?php else : ?>
70 <h4><?php echo esc_html( $value['title'] ) . wp_kses_post( $official_badge ); ?></h4>
71 <?php endif; ?>
72
73 <?php if ( $meta_pills ) : ?>
74 <div class="tpt-integration-item__pills">
75 <?php foreach ( $meta_pills as $pill ) : ?>
76 <span class="tpt-integration-item__pill"><?php echo esc_html( $pill ); ?></span>
77 <?php endforeach; ?>
78 </div>
79 <?php endif; ?>
80
81 <p class="description">
82 <?php
83 echo wp_kses_post( $description ); // nosemgrep
84 ?>
85 </p>
86
87 </div>
88
89 <div class="tpt-integration-item__actions">
90 <?php if ( $action_links ) : ?>
91 <div class="tpt-integration-item__action-links">
92 <?php foreach ( $action_links as $action_link ) : ?>
93 <?php if ( empty( $action_link['url'] ) || empty( $action_link['label'] ) ) { continue; } ?>
94 <a class="tpt-integration-item__action-link"
95 target="<?php echo esc_attr( $action_link['target'] ?? '_blank' ); ?>"
96 <?php echo ( $action_link['target'] ?? '_blank' ) === '_blank' ? 'rel="noopener"' : ''; ?>
97 href="<?php echo esc_url( $action_link['url'] ); ?>">
98 <?php echo esc_html( $action_link['label'] ); ?> &rarr;
99 </a>
100 <?php endforeach; ?>
101 </div>
102 <?php endif; ?>
103 <div class="tpt-integration-item-checkbox">
104 <input
105 name="<?php echo esc_attr( $value['id'] ); ?>"
106 id="<?php echo esc_attr( $value['id'] ); ?>"
107 type="checkbox"
108 value="1"
109 <?php checked( $option_value, 'yes' ); ?>
110 class="tpt-toggle-switch"
111 />
112 <label for="<?php echo esc_attr( $value['id'] ); ?>">
113 <span data-tpt-toggle-switch-on><?php echo esc_attr( $value['on_label'] ); ?></span>
114 <span data-tpt-toggle-switch-off><?php echo esc_attr( $value['off_label'] ); ?></span>
115 </label>
116 </div>
117 </div>
118 </div>
119 </div>
120 </td>
121 </tr>
122 <?php
123 }
124 }
125