| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main ProductDescription class. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Elementor\Widgets\Single; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Helpers\Fns; |
| 11 |
use RadiusTheme\SB\Abstracts\ElementorWidgetBase; |
| 12 |
use RadiusTheme\SB\Elementor\Widgets\Controls\AddToCartSettings; |
| 13 |
|
| 14 |
// Do not allow directly accessing this file. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit( 'This script cannot be accessed directly.' ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Product Description class |
| 21 |
*/ |
| 22 |
class ProductAddToCart 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 add to cart', 'shopbuilder' ); |
| 31 |
$this->rtsb_base = 'rtsb-product-add-to-cart'; |
| 32 |
parent::__construct( $data, $args ); |
| 33 |
} |
| 34 |
/** |
| 35 |
* Widget Field |
| 36 |
* |
| 37 |
* @return array |
| 38 |
*/ |
| 39 |
public function widget_fields() { |
| 40 |
$fields = AddToCartSettings::widget_fields( $this ); |
| 41 |
return apply_filters( 'rtsb/elements/elementor/single/' . $this->rtsb_base, $fields, $this ); |
| 42 |
} |
| 43 |
/** |
| 44 |
* Set Widget Keyword. |
| 45 |
* |
| 46 |
* @return array |
| 47 |
*/ |
| 48 |
public function get_keywords() { |
| 49 |
return [ 'Cart' ] + parent::get_keywords(); |
| 50 |
} |
| 51 |
/** |
| 52 |
* Widget Field. |
| 53 |
* |
| 54 |
* @param array $controllers Control. |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
public function the_hooks( $controllers = null ) { |
| 59 |
if ( ! $controllers ) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
if ( ! empty( $controllers['quantity_style'] ) ) { |
| 64 |
if ( in_array( $controllers['quantity_style'], [ 'style-1', 'style-2' ] ) ) { |
| 65 |
add_action( |
| 66 |
'woocommerce_before_quantity_input_field', |
| 67 |
function() use ( $controllers ) { ?> |
| 68 |
<!-- Quantity Wrapper Start --> |
| 69 |
<div class="rtsb-quantity-box-group rtsb-quantity-box-group-<?php echo esc_attr( $controllers['quantity_style'] ); ?>"> |
| 70 |
<button type="button" class="rtsb-quantity-btn rtsb-quantity-minus"> |
| 71 |
<?php |
| 72 |
echo wp_kses( |
| 73 |
$controllers['decrement_icon_html'], |
| 74 |
[ |
| 75 |
'i' => [ |
| 76 |
'class' => [], |
| 77 |
'aria-hidden' => [], |
| 78 |
], |
| 79 |
] |
| 80 |
); |
| 81 |
?> |
| 82 |
</button> |
| 83 |
<?php |
| 84 |
} |
| 85 |
); |
| 86 |
add_action( |
| 87 |
'woocommerce_after_quantity_input_field', |
| 88 |
function() use ( $controllers ) { |
| 89 |
?> |
| 90 |
<button type="button" class="rtsb-quantity-btn rtsb-quantity-plus"> |
| 91 |
<?php |
| 92 |
echo wp_kses( |
| 93 |
$controllers['increment_icon_html'], |
| 94 |
[ |
| 95 |
'i' => [ |
| 96 |
'class' => [], |
| 97 |
'aria-hidden' => [], |
| 98 |
], |
| 99 |
] |
| 100 |
); |
| 101 |
?> |
| 102 |
</button> |
| 103 |
</div> |
| 104 |
<!-- Quantity Wrapper End --> |
| 105 |
<?php |
| 106 |
} |
| 107 |
); |
| 108 |
} |
| 109 |
if ( in_array( $controllers['quantity_style'], [ 'style-3', 'style-4' ] ) ) { |
| 110 |
add_action( |
| 111 |
'woocommerce_before_quantity_input_field', |
| 112 |
function() use ( $controllers ) { |
| 113 |
?> |
| 114 |
<!-- Quantity Wrapper Start --> |
| 115 |
<div class="rtsb-quantity-box-group rtsb-quantity-box-group-<?php echo esc_attr( $controllers['quantity_style'] ); ?>"> |
| 116 |
<div class="rtsb-qty-btns-group"> |
| 117 |
<button type="button" class="rtsb-quantity-btn rtsb-quantity-plus"> |
| 118 |
<?php |
| 119 |
echo wp_kses( |
| 120 |
$controllers['increment_icon_html'], |
| 121 |
[ |
| 122 |
'i' => [ |
| 123 |
'class' => [], |
| 124 |
'aria-hidden' => [], |
| 125 |
], |
| 126 |
] |
| 127 |
); |
| 128 |
?> |
| 129 |
</button> |
| 130 |
<button type="button" class="rtsb-quantity-btn rtsb-quantity-minus"> |
| 131 |
<?php |
| 132 |
echo wp_kses( |
| 133 |
$controllers['decrement_icon_html'], |
| 134 |
[ |
| 135 |
'i' => [ |
| 136 |
'class' => [], |
| 137 |
'aria-hidden' => [], |
| 138 |
], |
| 139 |
] |
| 140 |
); |
| 141 |
?> |
| 142 |
</button> |
| 143 |
</div> |
| 144 |
<?php |
| 145 |
} |
| 146 |
); |
| 147 |
add_action( |
| 148 |
'woocommerce_after_quantity_input_field', |
| 149 |
function() { |
| 150 |
?> |
| 151 |
</div> |
| 152 |
<!-- Quantity Wrapper End --> |
| 153 |
<?php |
| 154 |
} |
| 155 |
); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
} |
| 160 |
/** |
| 161 |
* Render Function |
| 162 |
* |
| 163 |
* @return void |
| 164 |
*/ |
| 165 |
protected function render() { |
| 166 |
global $product; |
| 167 |
$_product = $product; |
| 168 |
$product = Fns::get_product(); |
| 169 |
$controllers = $this->get_settings_for_display(); |
| 170 |
$controllers['increment_icon_html'] = Fns::icons_manager( $controllers['increment_icon'] ); |
| 171 |
$controllers['decrement_icon_html'] = Fns::icons_manager( $controllers['decrement_icon'] ); |
| 172 |
$controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] ); |
| 173 |
|
| 174 |
$this->the_hooks( $controllers ); |
| 175 |
$this->theme_support(); |
| 176 |
|
| 177 |
$data = [ |
| 178 |
'template' => 'elementor/single-product/add-to-cart', |
| 179 |
'controllers' => $controllers, |
| 180 |
'product_type' => $product ? $product->get_type() : '', |
| 181 |
]; |
| 182 |
Fns::load_template( $data['template'], $data ); |
| 183 |
|
| 184 |
$this->editor_cart_icon_script(); |
| 185 |
$this->theme_support( 'render_reset' ); |
| 186 |
$product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 187 |
} |
| 188 |
|
| 189 |
} |
| 190 |
|