PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.3
ShopBuilder – WooCommerce Builder For Elementor v2.6.3
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Elementor / Widgets / Single / ProductTabs.php

ProductTabs.php in ShopBuilder – WooCommerce Builder For Elementor 2.6.3, at app/Elementor/Widgets/Single/ProductTabs.php

209 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ProductDescription class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Elementor\Widgets\Single;
9
10 // Do not allow directly accessing this file.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 use WC_Product;
16 use RadiusTheme\SB\Helpers\Fns;
17 use RadiusTheme\SB\Helpers\BuilderFns;
18 use RadiusTheme\SB\Abstracts\ElementorWidgetBase;
19 use RadiusTheme\SB\Elementor\Widgets\Controls\ProductTabsSettings;
20
21 /**
22 * Product Description class
23 */
24 class ProductTabs extends ElementorWidgetBase {
25 /**
26 * Construct function
27 *
28 * @param array $data default array.
29 * @param mixed $args default arg.
30 */
31 public function __construct( $data = [], $args = null ) {
32 $this->rtsb_name = esc_html__( 'Product Tabs', 'shopbuilder' );
33 $this->rtsb_base = 'rtsb-product-tabs';
34 parent::__construct( $data, $args );
35 }
36
37 /**
38 * Widget Field
39 *
40 * @return array
41 */
42 public function widget_fields() {
43 return ProductTabsSettings::widget_fields( $this );
44 }
45
46 /**
47 * Set Widget Keyword.
48 *
49 * @return array
50 */
51 public function get_keywords() {
52 return [ 'Tabs' ] + parent::get_keywords();
53 }
54
55 /**
56 * Widget Field.
57 *
58 * @param array $controllers Control.
59 *
60 * @return void
61 */
62 public function apply_hooks() {
63 add_filter( 'woocommerce_product_tabs', [ $this, 'woocommerce_product_tabs' ], 20 );
64 add_filter( 'woocommerce_product_additional_information_heading', [ $this, 'additional_information_title_text' ], 20 );
65 add_filter( 'woocommerce_product_description_heading', [ $this, 'woocommerce_product_description_heading' ], 20 );
66 }
67
68 /**
69 * @return void
70 */
71 public function remove_hooks() {
72 remove_filter( 'woocommerce_product_tabs', [ $this, 'woocommerce_product_tabs' ], 20 );
73 remove_filter( 'woocommerce_product_additional_information_heading', [ $this, 'additional_information_title_text' ], 20 );
74 remove_filter( 'woocommerce_product_description_heading', [ $this, 'woocommerce_product_description_heading' ], 20 );
75 }
76
77 /**
78 * @param $title
79 *
80 * @return mixed|string
81 */
82 public function woocommerce_product_description_heading( $title ) {
83 $controllers = $this->get_settings_for_display();
84
85 return $controllers['description_title_text'] ?? '';
86 }
87
88
89 /**
90 * @param $title
91 *
92 * @return mixed|string
93 */
94 public function additional_information_title_text( $title ) {
95 $controllers = $this->get_settings_for_display();
96
97 return $controllers['additional_information_title_text'] ?? '';
98 }
99
100 /**
101 * Undocumented function
102 *
103 * @return void
104 */
105 public function product_page_script() {
106 if ( ! $this->is_edit_mode() ) {
107 return;
108 }
109 ?>
110 <script type="text/javascript">
111 window.rtsbProductPageInit();
112 </script>
113 <?php
114 }
115
116 /**
117 * Product Tabs.
118 *
119 * @param array $tabs Existing tabs.
120 *
121 * @return array
122 */
123 public function woocommerce_product_tabs( $tabs ) {
124 global $product;
125
126 if ( ! $product instanceof WC_Product ) {
127 $product = wc_get_product();
128 }
129
130 $controllers = $this->get_settings_for_display();
131 $description = $product ? $product->get_description() : '';
132
133 if ( $this->is_edit_mode() ) {
134 add_filter(
135 'the_content',
136 function () {
137 return "This is only for preview text. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text.";
138 },
139 99
140 );
141 }
142
143 if ( empty( $controllers['description'] ) || empty( $description ) ) {
144 unset( $tabs['description'] );
145 } elseif ( ! empty( $controllers['description_nav_text'] ) ) {
146 $tabs['description']['title'] = $controllers['description_nav_text'];
147 }
148
149 if ( empty( $controllers['additional_information'] ) ) {
150 unset( $tabs['additional_information'] );
151 } elseif ( ! empty( $tabs['additional_information'] ) && ! empty( $controllers['additional_information_nav_text'] ) ) {
152 $tabs['additional_information']['title'] = $controllers['additional_information_nav_text'];
153 }
154
155 if ( empty( $controllers['reviews'] ) ) {
156 unset( $tabs['reviews'] );
157 } elseif ( ! empty( $controllers['reviews_nav_text'] ) ) {
158 $tabs['reviews']['title'] = $controllers['reviews_nav_text'];
159 }
160
161 return $tabs;
162 }
163
164 /**
165 * Render Function
166 *
167 * @return void
168 */
169 protected function render() {
170 global $product, $post;
171 $_post = $post;
172 $_product = $product;
173 $product = Fns::get_product();
174 $controllers = $this->get_settings_for_display();
175 if ( $this->is_builder_mode() ) {
176 // Overriding Global.
177 $this->product_page_script();
178 $post = get_post( Fns::get_prepared_product_id() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
179 }
180 if ( ! $this->is_edit_mode() && BuilderFns::is_builder_preview() ) {
181 add_filter(
182 'the_content',
183 function ( $content ) use ( $product ) {
184 $content = $product->get_description();
185 return $content;
186 },
187 1
188 );
189 }
190
191 $this->apply_hooks();
192 $this->theme_support();
193
194 $data = [
195 'template' => 'elementor/single-product/product-tabs',
196 'controllers' => $controllers,
197 ];
198 $data = apply_filters( 'rtsb/elements/elementor/render/' . $this->rtsb_base, $data, $this );
199 Fns::load_template( $data['template'], $data );
200
201 $this->remove_hooks();
202
203 $this->theme_support( 'render_reset' );
204
205 $post = $_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
206 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
207 }
208 }
209