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

199 lines 5.2 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 RadiusTheme\SB\Abstracts\ElementorWidgetBase;
16 use RadiusTheme\SB\Elementor\Widgets\Controls\ProductTabsSettings;
17 use RadiusTheme\SB\Helpers\BuilderFns;
18 use RadiusTheme\SB\Helpers\ElementorDataMap;
19 use RadiusTheme\SB\Helpers\Fns;
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 * @param $tabs
118 *
119 * @return mixed
120 */
121 public function woocommerce_product_tabs( $tabs ) {
122 $controllers = $this->get_settings_for_display();
123 if ( $this->is_edit_mode() ) {
124 add_filter(
125 'the_content',
126 function ( $content ) {
127 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.";
128 },
129 99
130 );
131 }
132 if ( empty( $controllers['description'] ) ) {
133 unset( $tabs['description'] );
134 } elseif ( ! empty( $controllers['description_nav_text'] ) ) {
135 $tabs['description']['title'] = $controllers['description_nav_text'];
136 }
137 if ( empty( $controllers['additional_information'] ) ) {
138 unset( $tabs['additional_information'] );
139 } elseif ( ! empty( $tabs['additional_information'] ) && ! empty( $controllers['additional_information_nav_text'] ) ) {
140 $tabs['additional_information']['title'] = $controllers['additional_information_nav_text'];
141 }
142
143 if ( empty( $controllers['reviews'] ) ) {
144 unset( $tabs['reviews'] );
145 } elseif ( ! empty( $controllers['reviews_nav_text'] ) ) {
146 $tabs['reviews']['title'] = $controllers['reviews_nav_text'];
147 }
148
149 return $tabs;
150 }
151
152 /**
153 * Render Function
154 *
155 * @return void
156 */
157 protected function render() {
158 global $product, $post;
159 $_post = $post;
160 $_product = $product;
161 $product = Fns::get_product();
162 $controllers = $this->get_settings_for_display();
163 if ( $this->is_builder_mode() ) {
164 // Overriding Global.
165 $this->product_page_script();
166 $post = get_post( Fns::get_prepared_product_id() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
167 }
168 if ( ! $this->is_edit_mode() && BuilderFns::is_builder_preview() ) {
169 add_filter(
170 'the_content',
171 function ( $content ) use ( $product ) {
172 $content = $product->get_description();
173 return $content;
174 },
175 1
176 );
177 }
178
179 // wp_enqueue_style( 'woodmart-style' );
180
181 $this->apply_hooks();
182 $this->theme_support();
183
184 $data = [
185 'template' => 'elementor/single-product/product-tabs',
186 'controllers' => $controllers,
187 ];
188 $data = apply_filters( 'rtsb/elements/elementor/render/' . $this->rtsb_base, $data, $this );
189 Fns::load_template( $data['template'], $data );
190
191 $this->remove_hooks();
192
193 $this->theme_support( 'render_reset' );
194
195 $post = $_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
196 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
197 }
198 }
199