| 1 |
<?php |
| 2 |
/** |
| 3 |
* Woo Checkout Sticky Sidebar widget. |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace King_Addons; |
| 9 |
|
| 10 |
use Elementor\Controls_Manager; |
| 11 |
use Elementor\Widget_Base; |
| 12 |
use King_Addons\Woo_Builder\Context as Woo_Context; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Placeholder sticky sidebar (Pro-only rendering). |
| 20 |
*/ |
| 21 |
class Woo_Checkout_Sticky_Sidebar extends Widget_Base |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Widget slug. |
| 25 |
* |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
public function get_name(): string |
| 29 |
{ |
| 30 |
return 'woo_checkout_sticky_sidebar'; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Widget title. |
| 35 |
* |
| 36 |
* @return string |
| 37 |
*/ |
| 38 |
public function get_title(): string |
| 39 |
{ |
| 40 |
return esc_html__('Checkout Sticky Sidebar', 'king-addons'); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Widget icon. |
| 45 |
* |
| 46 |
* @return string |
| 47 |
*/ |
| 48 |
public function get_icon(): string |
| 49 |
{ |
| 50 |
return 'eicon-sticky-note'; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Widget categories. |
| 55 |
* |
| 56 |
* @return array<int,string> |
| 57 |
*/ |
| 58 |
public function get_categories(): array |
| 59 |
{ |
| 60 |
return ['king-addons-woo-builder']; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Register controls. |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function get_custom_help_url() |
| 69 |
{ |
| 70 |
return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue'; |
| 71 |
} |
| 72 |
|
| 73 |
protected function register_controls(): void |
| 74 |
{ |
| 75 |
$this->start_controls_section( |
| 76 |
'section_content', |
| 77 |
[ |
| 78 |
'label' => esc_html__('Content', 'king-addons'), |
| 79 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 80 |
] |
| 81 |
); |
| 82 |
|
| 83 |
$this->add_control( |
| 84 |
'title_text', |
| 85 |
[ |
| 86 |
'label' => esc_html__('Sidebar Title', 'king-addons'), |
| 87 |
'type' => Controls_Manager::TEXT, |
| 88 |
'default' => esc_html__('Order Summary', 'king-addons'), |
| 89 |
] |
| 90 |
); |
| 91 |
|
| 92 |
$this->add_control( |
| 93 |
'sticky_offset', |
| 94 |
[ |
| 95 |
'label' => sprintf(__('Top Offset (px) (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'), |
| 96 |
'type' => Controls_Manager::NUMBER, |
| 97 |
'default' => 20, |
| 98 |
] |
| 99 |
); |
| 100 |
|
| 101 |
$this->add_control( |
| 102 |
'disable_below', |
| 103 |
[ |
| 104 |
'label' => sprintf(__('Disable sticky below (px) (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'), |
| 105 |
'type' => Controls_Manager::NUMBER, |
| 106 |
'default' => 768, |
| 107 |
] |
| 108 |
); |
| 109 |
|
| 110 |
$this->end_controls_section(); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Render widget output (Free notice). |
| 115 |
* |
| 116 |
* @return void |
| 117 |
*/ |
| 118 |
protected function render(): void |
| 119 |
{ |
| 120 |
if (!Woo_Context::maybe_render_context_notice('checkout')) { |
| 121 |
return; |
| 122 |
} |
| 123 |
|
| 124 |
$in_builder = class_exists('King_Addons\\Woo_Builder\\Context') && Woo_Context::is_editing_template_type('checkout'); |
| 125 |
if (!function_exists('is_checkout') || (!is_checkout() && !$in_builder) || (function_exists('is_order_received_page') && is_order_received_page())) { |
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
if (!function_exists('woocommerce_order_review')) { |
| 130 |
return; |
| 131 |
} |
| 132 |
|
| 133 |
if (!king_addons_can_use_pro()) { |
| 134 |
if (Woo_Context::is_editor()) { |
| 135 |
echo '<div class="king-addons-woo-builder-notice">'; |
| 136 |
echo esc_html__('Sticky order sidebar is available in Pro.', 'king-addons'); |
| 137 |
echo '</div>'; |
| 138 |
} |
| 139 |
return; |
| 140 |
} |
| 141 |
|
| 142 |
$settings = $this->get_settings_for_display(); |
| 143 |
$offset = isset($settings['sticky_offset']) ? (int) $settings['sticky_offset'] : 20; |
| 144 |
$disable_below = isset($settings['disable_below']) ? (int) $settings['disable_below'] : 768; |
| 145 |
|
| 146 |
echo '<aside class="ka-woo-checkout-sticky" data-ka-sticky="true" data-ka-sticky-offset="' . esc_attr($offset) . '" data-ka-sticky-breakpoint="' . esc_attr($disable_below) . '">'; |
| 147 |
if (!empty($settings['title_text'])) { |
| 148 |
echo '<h4 class="ka-woo-checkout-sticky__title">' . esc_html($settings['title_text']) . '</h4>'; |
| 149 |
} |
| 150 |
woocommerce_order_review(); |
| 151 |
echo '</aside>'; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|