| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Main ProductDescription class. |
| 5 |
* |
| 6 |
* @package RadiusTheme\SB |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace RadiusTheme\SB\Elementor\Widgets\Single; |
| 10 |
|
| 11 |
use RadiusTheme\SB\Helpers\Fns; |
| 12 |
use RadiusTheme\SB\Traits\ActionBtnTraits; |
| 13 |
use RadiusTheme\SB\Abstracts\ElementorWidgetBase; |
| 14 |
use RadiusTheme\SB\Elementor\Widgets\Controls\ActionsBtnSettings; |
| 15 |
|
| 16 |
// Do not allow directly accessing this file. |
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit( 'This script cannot be accessed directly.' ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Product Description class |
| 23 |
*/ |
| 24 |
class ActionsButton extends ElementorWidgetBase { |
| 25 |
/** |
| 26 |
* Action Button Traits. |
| 27 |
*/ |
| 28 |
use ActionBtnTraits; |
| 29 |
|
| 30 |
/** |
| 31 |
* Construct function |
| 32 |
* |
| 33 |
* @param array $data default array. |
| 34 |
* @param mixed $args default arg. |
| 35 |
*/ |
| 36 |
public function __construct( $data = [], $args = null ) { |
| 37 |
$this->rtsb_name = esc_html__( 'Actions Button', 'shopbuilder' ); |
| 38 |
$this->rtsb_base = 'rtsb-actions-button'; |
| 39 |
parent::__construct( $data, $args ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Widget Field |
| 44 |
* |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function widget_fields() { |
| 48 |
return ActionsBtnSettings::widget_fields( $this ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Set Widget Keyword. |
| 53 |
* |
| 54 |
* @return array |
| 55 |
*/ |
| 56 |
public function get_keywords() { |
| 57 |
return [ 'Compare', 'Wishlist' ] + parent::get_keywords(); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Widget Field. |
| 62 |
* |
| 63 |
* @param array $controllers Control. |
| 64 |
* |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
public function apply_hooks() { |
| 68 |
add_filter( 'rtsb/module/wishlist/button_params', [ $this, 'wishlist_button_params' ], 99 ); |
| 69 |
add_filter( 'rtsb/module/compare/button_params', [ $this, 'compare_button_params' ], 99 ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* @return void |
| 74 |
*/ |
| 75 |
public function remove_hooks() { |
| 76 |
remove_filter( 'rtsb/module/wishlist/button_params', [ $this, 'wishlist_button_params' ], 99 ); |
| 77 |
remove_filter( 'rtsb/module/compare/button_params', [ $this, 'compare_button_params' ], 99 ); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* @param $params |
| 82 |
* |
| 83 |
* @return mixed |
| 84 |
*/ |
| 85 |
public function wishlist_button_params( $params ) { |
| 86 |
$controllers = $this->get_settings_for_display(); |
| 87 |
if ( ! empty( $controllers['wishlist_button_text'] ) ) { |
| 88 |
$params['button_text'] = $controllers['wishlist_button_text']; |
| 89 |
$params['show_button_text'] = true; |
| 90 |
} |
| 91 |
|
| 92 |
return $params; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* @param $params |
| 97 |
* |
| 98 |
* @return mixed |
| 99 |
*/ |
| 100 |
public function compare_button_params( $params ) { |
| 101 |
$controllers = $this->get_settings_for_display(); |
| 102 |
if ( ! empty( $controllers['comparison_button_text'] ) ) { |
| 103 |
$params['button_text'] = $controllers['comparison_button_text']; |
| 104 |
$params['show_button_text'] = true; |
| 105 |
} |
| 106 |
|
| 107 |
return $params; |
| 108 |
} |
| 109 |
/** |
| 110 |
* Render Function |
| 111 |
* |
| 112 |
* @return void |
| 113 |
*/ |
| 114 |
protected function render() { |
| 115 |
global $post, $product; |
| 116 |
$_product = $product; |
| 117 |
$product = Fns::get_product(); |
| 118 |
$controllers = $this->get_settings_for_display(); |
| 119 |
$this->action_button_icon_modify(); |
| 120 |
$this->apply_hooks(); |
| 121 |
$this->theme_support(); |
| 122 |
|
| 123 |
ob_start(); |
| 124 |
if ( ! empty( $controllers['wishlist_button'] ) ) { |
| 125 |
echo '<div class="wishlist-wrapper button-item">'; |
| 126 |
do_action( 'rtsb/modules/wishlist/frontend/display' ); |
| 127 |
echo '</div>'; |
| 128 |
} |
| 129 |
if ( ! empty( $controllers['button_separator'] ) ) { |
| 130 |
echo '<div class="button-item button-separator">'; |
| 131 |
echo esc_html( $controllers['button_separator'] ); |
| 132 |
echo '</div>'; |
| 133 |
} |
| 134 |
if ( ! empty( $controllers['comparison_button'] ) ) { |
| 135 |
echo '<div class="compare-wrapper button-item">'; |
| 136 |
do_action( 'rtsb/modules/compare/frontend/display' ); |
| 137 |
echo '</div>'; |
| 138 |
} |
| 139 |
$button_html = ob_get_clean(); |
| 140 |
|
| 141 |
if ( empty( $button_html ) && $this->is_builder_mode() ) { |
| 142 |
$button_html = $this->rtsb_name; |
| 143 |
} |
| 144 |
|
| 145 |
$data = [ |
| 146 |
'template' => 'elementor/single-product/actions-button', |
| 147 |
'controllers' => $controllers, |
| 148 |
'content' => $button_html, |
| 149 |
]; |
| 150 |
|
| 151 |
Fns::load_template( $data['template'], $data ); |
| 152 |
|
| 153 |
$this->remove_hooks(); |
| 154 |
|
| 155 |
$this->theme_support( 'render_reset' ); |
| 156 |
|
| 157 |
$product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 158 |
$this->action_button_icon_set_default(); |
| 159 |
} |
| 160 |
} |
| 161 |
|