| 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 |
$fields = ProductTabsSettings::widget_fields( $this ); |
| 42 |
return apply_filters( 'rtsb/elements/elementor/single/' . $this->rtsb_base, $fields, $this ); |
| 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 |
* Undocumented function |
| 54 |
* |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function product_page_script() { ?> |
| 58 |
<script type="text/javascript"> |
| 59 |
jQuery( function( $ ) { |
| 60 |
// comment-form-rating |
| 61 |
$( '.rtsb-product-tabs #rating' ) |
| 62 |
.hide() |
| 63 |
.before( |
| 64 |
'<p class="stars">\ |
| 65 |
<span>\ |
| 66 |
<a class="star-1" href="#">1</a>\ |
| 67 |
<a class="star-2" href="#">2</a>\ |
| 68 |
<a class="star-3" href="#">3</a>\ |
| 69 |
<a class="star-4" href="#">4</a>\ |
| 70 |
<a class="star-5" href="#">5</a>\ |
| 71 |
</span>\ |
| 72 |
</p>' |
| 73 |
); |
| 74 |
$( '.rtsb-product-tabs .woocommerce-tabs' ).trigger( 'init' ); |
| 75 |
// Must need this line. |
| 76 |
}); |
| 77 |
</script> |
| 78 |
<?php |
| 79 |
} |
| 80 |
/** |
| 81 |
* Widget Field. |
| 82 |
* |
| 83 |
* @param array $controllers Control. |
| 84 |
* |
| 85 |
* @return void |
| 86 |
*/ |
| 87 |
public function the_hooks( $controllers = null ) { |
| 88 |
if ( ! $controllers ) { |
| 89 |
return; |
| 90 |
} |
| 91 |
add_filter( |
| 92 |
'woocommerce_product_tabs', |
| 93 |
function( $array ) use ( $controllers ) { |
| 94 |
if ( empty( $controllers['description'] ) ) { |
| 95 |
unset( $array['description'] ); |
| 96 |
} |
| 97 |
if ( empty( $controllers['additional_information'] ) ) { |
| 98 |
unset( $array['additional_information'] ); |
| 99 |
} |
| 100 |
if ( empty( $controllers['reviews'] ) ) { |
| 101 |
unset( $array['reviews'] ); |
| 102 |
} |
| 103 |
return $array; |
| 104 |
} |
| 105 |
); |
| 106 |
if( ! empty( $controllers['layout_style'] ) ){ |
| 107 |
add_action('rtsb/elements/elementor/render/tabs/content', 'woocommerce_output_product_data_tabs', 10); |
| 108 |
} |
| 109 |
} |
| 110 |
/** |
| 111 |
* Render Function |
| 112 |
* |
| 113 |
* @return void |
| 114 |
*/ |
| 115 |
protected function render() { |
| 116 |
global $product, $post; |
| 117 |
$_post = $post; |
| 118 |
$_product = $product; |
| 119 |
$product = Fns::get_product(); |
| 120 |
$controllers = $this->get_settings_for_display(); |
| 121 |
if ( $this->is_builder_mode() ) { |
| 122 |
|
| 123 |
// Overriding Global. |
| 124 |
$post = get_post( Fns::get_prepared_product_id() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 125 |
$this->product_page_script(); |
| 126 |
add_filter( |
| 127 |
'the_content', |
| 128 |
function( $content ) use ( $product ) { |
| 129 |
$content = $product->get_description(); |
| 130 |
return $content; |
| 131 |
}, |
| 132 |
1 |
| 133 |
); |
| 134 |
} |
| 135 |
|
| 136 |
$this->the_hooks( $controllers ); |
| 137 |
$this->theme_support(); |
| 138 |
|
| 139 |
|
| 140 |
$data = [ |
| 141 |
'template' => 'elementor/single-product/product-tabs', |
| 142 |
'controllers' => $controllers, |
| 143 |
]; |
| 144 |
$data = apply_filters( 'rtsb/elements/elementor/render/' . $this->rtsb_base, $data, $this ); |
| 145 |
Fns::load_template( $data['template'], $data ); |
| 146 |
|
| 147 |
$this->theme_support( 'render_reset' ); |
| 148 |
|
| 149 |
$post = $_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 150 |
$product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 151 |
} |
| 152 |
|
| 153 |
} |
| 154 |
|