| 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\Fns; |
| 18 |
|
| 19 |
/** |
| 20 |
* Product Description class |
| 21 |
*/ |
| 22 |
class ProductTabs extends ElementorWidgetBase { |
| 23 |
/** |
| 24 |
* Construct function |
| 25 |
* |
| 26 |
* @param array $data default array. |
| 27 |
* @param mixed $args default arg. |
| 28 |
*/ |
| 29 |
public function __construct( $data = [], $args = null ) { |
| 30 |
$this->rtsb_name = esc_html__( 'Product Tabs', 'shopbuilder' ); |
| 31 |
$this->rtsb_base = 'rtsb-product-tabs'; |
| 32 |
parent::__construct( $data, $args ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Widget Field |
| 37 |
* |
| 38 |
* @return array |
| 39 |
*/ |
| 40 |
public function widget_fields() { |
| 41 |
return ProductTabsSettings::widget_fields( $this ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Set Widget Keyword. |
| 46 |
* |
| 47 |
* @return array |
| 48 |
*/ |
| 49 |
public function get_keywords() { |
| 50 |
return [ 'Tabs' ] + parent::get_keywords(); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Widget Field. |
| 55 |
* |
| 56 |
* @param array $controllers Control. |
| 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 |
/** |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
public function remove_hooks() { |
| 71 |
remove_filter( 'woocommerce_product_tabs', [ $this, 'woocommerce_product_tabs' ], 20 ); |
| 72 |
remove_filter( 'woocommerce_product_additional_information_heading', [ $this, 'additional_information_title_text' ], 20 ); |
| 73 |
remove_filter( 'woocommerce_product_description_heading', [ $this, 'woocommerce_product_description_heading' ], 20 ); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* @param $title |
| 78 |
* |
| 79 |
* @return mixed|string |
| 80 |
*/ |
| 81 |
public function woocommerce_product_description_heading( $title ) { |
| 82 |
$controllers = $this->get_settings_for_display(); |
| 83 |
|
| 84 |
return $controllers['description_title_text'] ?? ''; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
/** |
| 89 |
* @param $title |
| 90 |
* |
| 91 |
* @return mixed|string |
| 92 |
*/ |
| 93 |
public function additional_information_title_text( $title ) { |
| 94 |
$controllers = $this->get_settings_for_display(); |
| 95 |
|
| 96 |
return $controllers['additional_information_title_text'] ?? ''; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Undocumented function |
| 101 |
* |
| 102 |
* @return void |
| 103 |
*/ |
| 104 |
public function product_page_script() { ?> |
| 105 |
<script type="text/javascript"> |
| 106 |
jQuery( function( $ ) { |
| 107 |
// comment-form-rating |
| 108 |
$( '.rtsb-product-tabs #rating' ) |
| 109 |
.hide() |
| 110 |
.before( |
| 111 |
'<p class="stars">\ |
| 112 |
<span>\ |
| 113 |
<a class="star-1" href="#">1</a>\ |
| 114 |
<a class="star-2" href="#">2</a>\ |
| 115 |
<a class="star-3" href="#">3</a>\ |
| 116 |
<a class="star-4" href="#">4</a>\ |
| 117 |
<a class="star-5" href="#">5</a>\ |
| 118 |
</span>\ |
| 119 |
</p>' |
| 120 |
); |
| 121 |
$( '.rtsb-product-tabs .woocommerce-tabs' ).trigger( 'init' ); |
| 122 |
// Must need this line. |
| 123 |
}); |
| 124 |
</script> |
| 125 |
<?php |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* @param $tabs |
| 130 |
* |
| 131 |
* @return mixed |
| 132 |
*/ |
| 133 |
public function woocommerce_product_tabs( $tabs ) { |
| 134 |
$controllers = $this->get_settings_for_display(); |
| 135 |
if ( $this->is_edit_mode() ) { |
| 136 |
add_filter( 'the_content', |
| 137 |
function( $content ) { |
| 138 |
return "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."; |
| 139 |
}, |
| 140 |
1 |
| 141 |
); |
| 142 |
} |
| 143 |
if ( empty( $controllers['description'] ) ) { |
| 144 |
unset( $tabs['description'] ); |
| 145 |
} else if ( ! empty( $controllers['description_nav_text'] ) ) { |
| 146 |
$tabs['description']['title'] = $controllers['description_nav_text']; |
| 147 |
} |
| 148 |
if ( empty( $controllers['additional_information'] ) ) { |
| 149 |
unset( $tabs['additional_information'] ); |
| 150 |
} else if ( ! empty( $tabs['additional_information'] ) && ! empty( $controllers['additional_information_nav_text'] ) ) { |
| 151 |
$tabs['additional_information']['title'] = $controllers['additional_information_nav_text']; |
| 152 |
} |
| 153 |
|
| 154 |
if ( empty( $controllers['reviews'] ) ) { |
| 155 |
unset( $tabs['reviews'] ); |
| 156 |
} else if ( ! empty( $controllers['reviews_nav_text'] ) ) { |
| 157 |
$tabs['reviews']['title'] = $controllers['reviews_nav_text']; |
| 158 |
} |
| 159 |
|
| 160 |
return $tabs; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Render Function |
| 165 |
* |
| 166 |
* @return void |
| 167 |
*/ |
| 168 |
protected function render() { |
| 169 |
global $product, $post; |
| 170 |
$_post = $post; |
| 171 |
$_product = $product; |
| 172 |
$product = Fns::get_product(); |
| 173 |
$controllers = $this->get_settings_for_display(); |
| 174 |
if ( $this->is_builder_mode() ) { |
| 175 |
// Overriding Global. |
| 176 |
$this->product_page_script(); |
| 177 |
$post = get_post( Fns::get_prepared_product_id() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 178 |
} |
| 179 |
if ( ! $this->is_edit_mode() && $this->is_builder_mode() ){ |
| 180 |
add_filter( |
| 181 |
'the_content', |
| 182 |
function( $content ) use ( $product ) { |
| 183 |
$content = $product->get_description(); |
| 184 |
return $content; |
| 185 |
}, |
| 186 |
1 |
| 187 |
); |
| 188 |
} |
| 189 |
|
| 190 |
$this->apply_hooks(); |
| 191 |
$this->theme_support(); |
| 192 |
|
| 193 |
$data = [ |
| 194 |
'template' => 'elementor/single-product/product-tabs', |
| 195 |
'controllers' => $controllers, |
| 196 |
]; |
| 197 |
$data = apply_filters( 'rtsb/elements/elementor/render/' . $this->rtsb_base, $data, $this ); |
| 198 |
Fns::load_template( $data['template'], $data ); |
| 199 |
|
| 200 |
$this->remove_hooks(); |
| 201 |
|
| 202 |
$this->theme_support( 'render_reset' ); |
| 203 |
|
| 204 |
$post = $_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 205 |
$product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 206 |
} |
| 207 |
|
| 208 |
} |
| 209 |
|