PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.1
ShopBuilder – WooCommerce Builder For Elementor v3.2.1
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 3.2.1, at app/Elementor/Widgets/Single/ProductTabs.php

226 lines 5.9 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 * @return void
59 */
60 public function apply_hooks() {
61 add_filter( 'woocommerce_product_tabs', [ $this, 'woocommerce_product_tabs' ], 20 );
62 add_filter( 'woocommerce_product_additional_information_heading', [ $this, 'additional_information_title_text' ], 20 );
63 add_filter( 'woocommerce_product_description_heading', [ $this, 'woocommerce_product_description_heading' ], 20 );
64 }
65
66 /**
67 * @return void
68 */
69 public function remove_hooks() {
70 remove_filter( 'woocommerce_product_tabs', [ $this, 'woocommerce_product_tabs' ], 20 );
71 remove_filter( 'woocommerce_product_additional_information_heading', [ $this, 'additional_information_title_text' ], 20 );
72 remove_filter( 'woocommerce_product_description_heading', [ $this, 'woocommerce_product_description_heading' ], 20 );
73 }
74
75 /**
76 * Product Description
77 *
78 * @return mixed|string
79 */
80 public function woocommerce_product_description_heading() {
81 $controllers = $this->get_settings_for_display();
82
83 return $controllers['description_title_text'] ?? '';
84 }
85
86
87 /**
88 * Additional Information
89 *
90 * @return mixed|string
91 */
92 public function additional_information_title_text() {
93 $controllers = $this->get_settings_for_display();
94
95 return $controllers['additional_information_title_text'] ?? '';
96 }
97
98 /**
99 * Product Page Script
100 *
101 * @return void
102 */
103 public function product_page_script() {
104 if ( ! $this->is_edit_mode() ) {
105 return;
106 }
107 ?>
108 <script type="text/javascript">
109 if (!'<?php echo esc_attr( Fns::is_optimization_enabled() ); ?>') {
110 setTimeout(function() {
111 window.rtsbProductPageInit();
112 }, 1000);
113 } else {
114 if (typeof elementorFrontend !== 'undefined') {
115 elementorFrontend.hooks.addAction(
116 'frontend/element_ready/rtsb-product-tabs.default',
117 () => {
118 window.waitForRTSB((RTSB) => {
119 RTSB.modules.get('singleProductTabs')?.refresh();
120 RTSB.modules.get('reviewFormStar')?.refresh();
121 RTSB.modules.get('addCartIcon')?.refresh();
122 RTSB.modules.get('productImage')?.refresh();
123 RTSB.modules.get('CartQuantityHandler')?.refresh();
124 });
125 }
126 );
127 }
128 }
129 </script>
130 <?php
131 }
132
133 /**
134 * Product Tabs.
135 *
136 * @param array $tabs Existing tabs.
137 *
138 * @return array
139 */
140 public function woocommerce_product_tabs( $tabs ) {
141 global $product;
142
143 if ( ! $product instanceof WC_Product ) {
144 $product = wc_get_product();
145 }
146
147 $controllers = $this->get_settings_for_display();
148 $description = $product ? $product->get_description() : '';
149
150 if ( $this->is_edit_mode() ) {
151 add_filter(
152 'the_content',
153 function () {
154 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.";
155 },
156 99
157 );
158 }
159
160 if ( empty( $controllers['description'] ) || empty( $description ) ) {
161 unset( $tabs['description'] );
162 } elseif ( ! empty( $controllers['description_nav_text'] ) ) {
163 $tabs['description']['title'] = $controllers['description_nav_text'];
164 }
165
166 if ( empty( $controllers['additional_information'] ) ) {
167 unset( $tabs['additional_information'] );
168 } elseif ( ! empty( $tabs['additional_information'] ) && ! empty( $controllers['additional_information_nav_text'] ) ) {
169 $tabs['additional_information']['title'] = $controllers['additional_information_nav_text'];
170 }
171
172 if ( empty( $controllers['reviews'] ) ) {
173 unset( $tabs['reviews'] );
174 } elseif ( ! empty( $controllers['reviews_nav_text'] ) ) {
175 $tabs['reviews']['title'] = $controllers['reviews_nav_text'];
176 }
177
178 return $tabs;
179 }
180
181 /**
182 * Render Function
183 *
184 * @return void
185 */
186 protected function render() {
187 global $product, $post;
188 $_post = $post;
189 $_product = $product;
190 $product = Fns::get_product();
191 $controllers = $this->get_settings_for_display();
192 if ( $this->is_builder_mode() ) {
193 // Overriding Global.
194 $this->product_page_script();
195 $post = get_post( Fns::get_prepared_product_id() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
196 }
197 if ( ! $this->is_edit_mode() && BuilderFns::is_builder_preview() ) {
198 add_filter(
199 'the_content',
200 function ( $content ) use ( $product ) {
201 $content = $product->get_description();
202 return $content;
203 },
204 1
205 );
206 }
207
208 $this->apply_hooks();
209 $this->theme_support();
210
211 $data = [
212 'template' => 'elementor/single-product/product-tabs',
213 'controllers' => $controllers,
214 ];
215 $data = apply_filters( 'rtsb/elements/elementor/render/' . $this->rtsb_base, $data, $this );
216 Fns::load_template( $data['template'], $data );
217
218 $this->remove_hooks();
219
220 $this->theme_support( 'render_reset' );
221
222 $post = $_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
223 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
224 }
225 }
226