| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor Classes. |
| 4 |
* |
| 5 |
* @package cartflows |
| 6 |
*/ |
| 7 |
|
| 8 |
use Elementor\Controls_Manager; |
| 9 |
use Elementor\Widget_Base; |
| 10 |
use Elementor\Group_Control_Typography; |
| 11 |
use Elementor\Group_Control_Background; |
| 12 |
use Elementor\Group_Control_Border; |
| 13 |
use Elementor\Group_Control_Box_Shadow; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Optin Form Widget |
| 21 |
* |
| 22 |
* @since 1.6.15 |
| 23 |
*/ |
| 24 |
class CartFlows_Optin_Form extends Widget_Base { |
| 25 |
|
| 26 |
/** |
| 27 |
* Module should load or not. |
| 28 |
* |
| 29 |
* @since 1.6.15 |
| 30 |
* @access public |
| 31 |
* @param string $step_type Current step type. |
| 32 |
* |
| 33 |
* @return bool true|false. |
| 34 |
*/ |
| 35 |
public static function is_enable( $step_type ) { |
| 36 |
|
| 37 |
if ( 'optin' === $step_type && wcf()->is_woo_active ) { |
| 38 |
return true; |
| 39 |
} |
| 40 |
return false; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Retrieve the widget name. |
| 45 |
* |
| 46 |
* @since 1.6.15 |
| 47 |
* |
| 48 |
* @access public |
| 49 |
* |
| 50 |
* @return string Widget name. |
| 51 |
*/ |
| 52 |
public function get_name() { |
| 53 |
return 'optin-form'; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Retrieve the widget title. |
| 58 |
* |
| 59 |
* @since 1.6.15 |
| 60 |
* |
| 61 |
* @access public |
| 62 |
* |
| 63 |
* @return string Widget title. |
| 64 |
*/ |
| 65 |
public function get_title() { |
| 66 |
return __( 'Optin Form', 'cartflows' ); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Retrieve the widget icon. |
| 71 |
* |
| 72 |
* @since 1.6.15 |
| 73 |
* |
| 74 |
* @access public |
| 75 |
* |
| 76 |
* @return string Widget icon. |
| 77 |
*/ |
| 78 |
public function get_icon() { |
| 79 |
return 'wcf-brand-icon wcf-el-icon-optin-form'; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Retrieve the list of categories the widget belongs to. |
| 84 |
* |
| 85 |
* Used to determine where to display the widget in the editor. |
| 86 |
* |
| 87 |
* Note that currently Elementor supports only one category. |
| 88 |
* When multiple categories passed, Elementor uses the first one. |
| 89 |
* |
| 90 |
* @since 1.6.15 |
| 91 |
* |
| 92 |
* @access public |
| 93 |
* |
| 94 |
* @return array Widget categories. |
| 95 |
*/ |
| 96 |
public function get_categories() { |
| 97 |
return array( 'cartflows-widgets' ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Settings |
| 102 |
* |
| 103 |
* @since 1.6.15 |
| 104 |
* @var object $settings |
| 105 |
*/ |
| 106 |
public static $settings; |
| 107 |
|
| 108 |
/** |
| 109 |
* Retrieve Widget Keywords. |
| 110 |
* |
| 111 |
* @since 1.6.15 |
| 112 |
* @access public |
| 113 |
* |
| 114 |
* @return string Widget keywords. |
| 115 |
*/ |
| 116 |
public function get_keywords() { |
| 117 |
return array( 'cartflows', 'optin', 'form' ); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Register cart controls controls. |
| 122 |
* |
| 123 |
* @since 1.6.15 |
| 124 |
* @access protected |
| 125 |
*/ |
| 126 |
protected function register_controls() { |
| 127 |
|
| 128 |
// Style Tab. |
| 129 |
$this->register_general_style_controls(); |
| 130 |
$this->register_input_style_controls(); |
| 131 |
$this->register_button_style_controls(); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Function to get skin types. |
| 136 |
* |
| 137 |
* @since 1.6.15 |
| 138 |
* @access protected |
| 139 |
*/ |
| 140 |
protected function get_skin_types() { |
| 141 |
|
| 142 |
$skin_options = array( |
| 143 |
'default' => __( 'Default', 'cartflows' ), |
| 144 |
'floating-labels' => __( 'Floating Labels', 'cartflows' ), |
| 145 |
); |
| 146 |
|
| 147 |
return $skin_options; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Register General Style Controls. |
| 152 |
* |
| 153 |
* @since 1.6.15 |
| 154 |
* @access protected |
| 155 |
*/ |
| 156 |
protected function register_general_style_controls() { |
| 157 |
$this->start_controls_section( |
| 158 |
'section_general_style_fields', |
| 159 |
array( |
| 160 |
'label' => __( 'General', 'cartflows' ), |
| 161 |
'tab' => Controls_Manager::TAB_STYLE, |
| 162 |
) |
| 163 |
); |
| 164 |
|
| 165 |
$this->add_control( |
| 166 |
'general_primary_color', |
| 167 |
array( |
| 168 |
'label' => __( 'Primary Color', 'cartflows' ), |
| 169 |
'type' => Controls_Manager::COLOR, |
| 170 |
'default' => '', |
| 171 |
'selectors' => array( |
| 172 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order' => 'background-color: {{VALUE}}; border-color: {{VALUE}};', |
| 173 |
), |
| 174 |
) |
| 175 |
); |
| 176 |
|
| 177 |
$this->add_group_control( |
| 178 |
Group_Control_Typography::get_type(), |
| 179 |
array( |
| 180 |
'name' => 'general_typography', |
| 181 |
'label' => 'Typography', |
| 182 |
'selector' => '{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout label, {{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout input, {{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order', |
| 183 |
) |
| 184 |
); |
| 185 |
|
| 186 |
$this->end_controls_section(); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Register Input Fields Style Controls. |
| 191 |
* |
| 192 |
* @since 1.6.15 |
| 193 |
* @access protected |
| 194 |
*/ |
| 195 |
protected function register_input_style_controls() { |
| 196 |
$this->start_controls_section( |
| 197 |
'input_section', |
| 198 |
array( |
| 199 |
'label' => __( 'Input Fields', 'cartflows' ), |
| 200 |
'tab' => Controls_Manager::TAB_STYLE, |
| 201 |
) |
| 202 |
); |
| 203 |
|
| 204 |
$this->add_control( |
| 205 |
'input_skins', |
| 206 |
array( |
| 207 |
'label' => __( 'Style', 'cartflows' ), |
| 208 |
'type' => Controls_Manager::SELECT, |
| 209 |
'default' => 'default', |
| 210 |
'options' => $this->get_skin_types(), |
| 211 |
) |
| 212 |
); |
| 213 |
|
| 214 |
$this->add_group_control( |
| 215 |
Group_Control_Typography::get_type(), |
| 216 |
array( |
| 217 |
'name' => 'input_text_typography', |
| 218 |
'label' => 'Typography', |
| 219 |
'selector' => '{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout label, {{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout input', |
| 220 |
) |
| 221 |
); |
| 222 |
|
| 223 |
$this->add_control( |
| 224 |
'label_color', |
| 225 |
array( |
| 226 |
'label' => __( 'Label Color', 'cartflows' ), |
| 227 |
'type' => Controls_Manager::COLOR, |
| 228 |
'selectors' => array( |
| 229 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout label' => 'color: {{VALUE}};', |
| 230 |
), |
| 231 |
) |
| 232 |
); |
| 233 |
|
| 234 |
$this->add_control( |
| 235 |
'input_bgcolor', |
| 236 |
array( |
| 237 |
'label' => __( 'Field Background Color', 'cartflows' ), |
| 238 |
'type' => Controls_Manager::COLOR, |
| 239 |
'selectors' => array( |
| 240 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout input' => 'background-color: {{VALUE}};', |
| 241 |
), |
| 242 |
) |
| 243 |
); |
| 244 |
|
| 245 |
$this->add_control( |
| 246 |
'input_color', |
| 247 |
array( |
| 248 |
'label' => __( 'Input Text / Placeholder Color', 'cartflows' ), |
| 249 |
'type' => Controls_Manager::COLOR, |
| 250 |
'selectors' => array( |
| 251 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout input' => 'color: {{VALUE}} !important;', |
| 252 |
), |
| 253 |
) |
| 254 |
); |
| 255 |
|
| 256 |
$this->add_control( |
| 257 |
'input_border_style', |
| 258 |
array( |
| 259 |
'label' => __( 'Border Style', 'cartflows' ), |
| 260 |
'type' => Controls_Manager::SELECT, |
| 261 |
'label_block' => false, |
| 262 |
'default' => '', |
| 263 |
'options' => array( |
| 264 |
'' => __( 'Inherit', 'cartflows' ), |
| 265 |
'solid' => __( 'Solid', 'cartflows' ), |
| 266 |
'double' => __( 'Double', 'cartflows' ), |
| 267 |
'dotted' => __( 'Dotted', 'cartflows' ), |
| 268 |
'dashed' => __( 'Dashed', 'cartflows' ), |
| 269 |
), |
| 270 |
'selectors' => array( |
| 271 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout input' => 'border-style: {{VALUE}};', |
| 272 |
), |
| 273 |
) |
| 274 |
); |
| 275 |
$this->add_control( |
| 276 |
'input_border_size', |
| 277 |
array( |
| 278 |
'label' => __( 'Border Width', 'cartflows' ), |
| 279 |
'type' => Controls_Manager::DIMENSIONS, |
| 280 |
'size_units' => array( 'px' ), |
| 281 |
'selectors' => array( |
| 282 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout input' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 283 |
), |
| 284 |
) |
| 285 |
); |
| 286 |
|
| 287 |
$this->add_control( |
| 288 |
'input_border_color', |
| 289 |
array( |
| 290 |
'label' => __( 'Border Color', 'cartflows' ), |
| 291 |
'type' => Controls_Manager::COLOR, |
| 292 |
'selectors' => array( |
| 293 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout input' => 'border-color: {{VALUE}};', |
| 294 |
), |
| 295 |
) |
| 296 |
); |
| 297 |
|
| 298 |
$this->add_responsive_control( |
| 299 |
'input_radius', |
| 300 |
array( |
| 301 |
'label' => __( 'Rounded Corners', 'cartflows' ), |
| 302 |
'type' => Controls_Manager::DIMENSIONS, |
| 303 |
'size_units' => array( 'px', 'em', '%' ), |
| 304 |
'selectors' => array( |
| 305 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout input' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 306 |
), |
| 307 |
) |
| 308 |
); |
| 309 |
|
| 310 |
$this->end_controls_section(); |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Register Button Style Controls. |
| 315 |
* |
| 316 |
* @since 1.6.15 |
| 317 |
* @access protected |
| 318 |
*/ |
| 319 |
protected function register_button_style_controls() { |
| 320 |
|
| 321 |
$this->start_controls_section( |
| 322 |
'button_section', |
| 323 |
array( |
| 324 |
'label' => __( 'Submit Button', 'cartflows' ), |
| 325 |
'tab' => Controls_Manager::TAB_STYLE, |
| 326 |
) |
| 327 |
); |
| 328 |
|
| 329 |
$this->add_group_control( |
| 330 |
Group_Control_Typography::get_type(), |
| 331 |
array( |
| 332 |
'name' => 'buttons_typography', |
| 333 |
'label' => 'Typography', |
| 334 |
'selector' => '{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review #payment button#place_order', |
| 335 |
) |
| 336 |
); |
| 337 |
|
| 338 |
$this->start_controls_tabs( 'tabs_button_style' ); |
| 339 |
|
| 340 |
$this->start_controls_tab( |
| 341 |
'tab_button_normal', |
| 342 |
array( |
| 343 |
'label' => __( 'Normal', 'cartflows' ), |
| 344 |
) |
| 345 |
); |
| 346 |
|
| 347 |
$this->add_control( |
| 348 |
'button_text_color', |
| 349 |
array( |
| 350 |
'label' => __( 'Text Color', 'cartflows' ), |
| 351 |
'type' => Controls_Manager::COLOR, |
| 352 |
'default' => '', |
| 353 |
'selectors' => array( |
| 354 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order' => 'color: {{VALUE}};', |
| 355 |
), |
| 356 |
) |
| 357 |
); |
| 358 |
|
| 359 |
$this->add_group_control( |
| 360 |
Group_Control_Background::get_type(), |
| 361 |
array( |
| 362 |
'name' => 'btn_background_color', |
| 363 |
'label' => __( 'Background Color', 'cartflows' ), |
| 364 |
'types' => array( 'classic', 'gradient' ), |
| 365 |
'selector' => '{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order', |
| 366 |
) |
| 367 |
); |
| 368 |
|
| 369 |
$this->add_group_control( |
| 370 |
Group_Control_Border::get_type(), |
| 371 |
array( |
| 372 |
'name' => 'btn_border', |
| 373 |
'label' => __( 'Border', 'cartflows' ), |
| 374 |
'selector' => '{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order', |
| 375 |
) |
| 376 |
); |
| 377 |
|
| 378 |
$this->add_responsive_control( |
| 379 |
'btn_border_radius', |
| 380 |
array( |
| 381 |
'label' => __( 'Rounded Corners', 'cartflows' ), |
| 382 |
'type' => Controls_Manager::DIMENSIONS, |
| 383 |
'size_units' => array( 'px', '%' ), |
| 384 |
'selectors' => array( |
| 385 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 386 |
), |
| 387 |
) |
| 388 |
); |
| 389 |
|
| 390 |
$this->add_group_control( |
| 391 |
Group_Control_Box_Shadow::get_type(), |
| 392 |
array( |
| 393 |
'name' => 'button_box_shadow', |
| 394 |
'selector' => '{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order', |
| 395 |
) |
| 396 |
); |
| 397 |
|
| 398 |
$this->end_controls_tab(); |
| 399 |
|
| 400 |
$this->start_controls_tab( |
| 401 |
'tab_button_hover', |
| 402 |
array( |
| 403 |
'label' => __( 'Hover', 'cartflows' ), |
| 404 |
) |
| 405 |
); |
| 406 |
|
| 407 |
$this->add_control( |
| 408 |
'btn_hover_color', |
| 409 |
array( |
| 410 |
'label' => __( 'Text Color', 'cartflows' ), |
| 411 |
'type' => Controls_Manager::COLOR, |
| 412 |
'selectors' => array( |
| 413 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order:hover' => 'color: {{VALUE}};', |
| 414 |
), |
| 415 |
) |
| 416 |
); |
| 417 |
|
| 418 |
$this->add_control( |
| 419 |
'button_hover_border_color', |
| 420 |
array( |
| 421 |
'label' => __( 'Border Hover Color', 'cartflows' ), |
| 422 |
'type' => Controls_Manager::COLOR, |
| 423 |
'selectors' => array( |
| 424 |
'{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order:hover' => 'border-color: {{VALUE}};', |
| 425 |
), |
| 426 |
) |
| 427 |
); |
| 428 |
|
| 429 |
$this->add_group_control( |
| 430 |
Group_Control_Background::get_type(), |
| 431 |
array( |
| 432 |
'name' => 'button_background_hover_color', |
| 433 |
'label' => __( 'Background Color', 'cartflows' ), |
| 434 |
'types' => array( 'classic', 'gradient' ), |
| 435 |
'selector' => '{{WRAPPER}} .wcf-el-optin-form.cartflows-elementor__optin-form .wcf-optin-form .checkout.woocommerce-checkout .wcf-order-wrap #order_review .woocommerce-checkout-payment button#place_order:hover', |
| 436 |
) |
| 437 |
); |
| 438 |
|
| 439 |
$this->end_controls_tab(); |
| 440 |
|
| 441 |
$this->end_controls_tabs(); |
| 442 |
|
| 443 |
$this->end_controls_section(); |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
/** |
| 448 |
* Cartflows Optin Form Styler. |
| 449 |
* |
| 450 |
* @since 1.6.15 |
| 451 |
* @access public |
| 452 |
*/ |
| 453 |
public function is_reload_preview_required() { |
| 454 |
return true; |
| 455 |
} |
| 456 |
|
| 457 |
/** |
| 458 |
* Render Optin Form output on the frontend. |
| 459 |
* |
| 460 |
* Written in PHP and used to generate the final HTML. |
| 461 |
* |
| 462 |
* @since 1.6.15 |
| 463 |
* @access protected |
| 464 |
*/ |
| 465 |
protected function render() { |
| 466 |
|
| 467 |
self::$settings = $this->get_settings_for_display(); |
| 468 |
|
| 469 |
/* Add elementor setting options to filters */ |
| 470 |
$this->dynamic_option_filters(); |
| 471 |
|
| 472 |
$checkout_id = get_the_id(); |
| 473 |
|
| 474 |
do_action( 'cartflows_elementor_before_optin_shortcode', $checkout_id ); |
| 475 |
|
| 476 |
?> |
| 477 |
<div class = "wcf-el-optin-form cartflows-elementor__optin-form"> |
| 478 |
<?php echo do_shortcode( '[cartflows_optin]' ); ?> |
| 479 |
</div> |
| 480 |
<?php |
| 481 |
|
| 482 |
} |
| 483 |
|
| 484 |
/** |
| 485 |
* Dynamic options of elementor and add filters. |
| 486 |
* |
| 487 |
* @since 1.6.15 |
| 488 |
*/ |
| 489 |
public function dynamic_option_filters() { |
| 490 |
|
| 491 |
$optin_fields = array( |
| 492 |
|
| 493 |
// Input Fields. |
| 494 |
array( |
| 495 |
'filter_slug' => 'wcf-input-fields-skins', |
| 496 |
'setting_name' => 'input_skins', |
| 497 |
), |
| 498 |
); |
| 499 |
|
| 500 |
if ( isset( $optin_fields ) && is_array( $optin_fields ) ) { |
| 501 |
|
| 502 |
foreach ( $optin_fields as $key => $field ) { |
| 503 |
|
| 504 |
$setting_name = $field['setting_name']; |
| 505 |
|
| 506 |
add_filter( |
| 507 |
'cartflows_optin_meta_' . $field['filter_slug'], |
| 508 |
function ( $value ) use ( $setting_name ) { |
| 509 |
|
| 510 |
$value = self::$settings[ $setting_name ]; |
| 511 |
|
| 512 |
return $value; |
| 513 |
}, |
| 514 |
10, |
| 515 |
1 |
| 516 |
); |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
do_action( 'cartflows_elementor_optin_options_filters', self::$settings ); |
| 521 |
} |
| 522 |
} |
| 523 |
|