← All changes
|
includes/helpers/Woo_Builder/Abstract_Checkout_Widget.php
+63
-1
51.1.44
→
51.1.87
View file →
| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace King_Addons; |
| 9 | 9 | |
| 10 | 10 | use Elementor\Widget_Base; |
| 11 | +use King_Addons\Woo_Builder\Context as Woo_Context; | |
| 11 | 12 | |
| 12 | 13 | if (!defined('ABSPATH')) { |
| 13 | 14 | exit; |
| 14 | 15 | } |
| @@ -18,8 +19,43 @@ | ||
| 18 | 19 | */ |
| 19 | 20 | abstract class Abstract_Checkout_Widget extends Widget_Base |
| 20 | 21 | { |
| 21 | 22 | /** |
| 23 | + * Check if we should render the widget. | |
| 24 | + * Returns true if in editor editing checkout template or on actual checkout page. | |
| 25 | + * | |
| 26 | + * @return bool | |
| 27 | + */ | |
| 28 | + protected function should_render(): bool | |
| 29 | + { | |
| 30 | + if (!$this->can_use_builder_widgets()) { | |
| 31 | + return false; | |
| 32 | + } | |
| 33 | + | |
| 34 | + // In editor mode editing checkout template | |
| 35 | + if (class_exists('King_Addons\\Woo_Builder\\Context') && Woo_Context::is_editing_template_type('checkout')) { | |
| 36 | + return true; | |
| 37 | + } | |
| 38 | + | |
| 39 | + // On actual checkout page | |
| 40 | + if (function_exists('is_checkout') && is_checkout() && !is_order_received_page()) { | |
| 41 | + return true; | |
| 42 | + } | |
| 43 | + | |
| 44 | + return false; | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Cart / checkout / account builder widgets are a Pro feature. | |
| 49 | + * | |
| 50 | + * @return bool | |
| 51 | + */ | |
| 52 | + protected function can_use_builder_widgets(): bool | |
| 53 | + { | |
| 54 | + return function_exists('king_addons_can_use_pro') && king_addons_can_use_pro(); | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 22 | 58 | * Render placeholder when checkout context is missing. |
| 23 | 59 | * |
| 24 | 60 | * @return void |
| 25 | 61 | */ |
| @@ -24,13 +60,39 @@ | ||
| 24 | 60 | * @return void |
| 25 | 61 | */ |
| 26 | 62 | protected function render_missing_checkout_notice(): void |
| 27 | 63 | { |
| 28 | - if (!\Elementor\Plugin::$instance->editor->is_edit_mode()) { | |
| 64 | + if (!class_exists('\Elementor\Plugin') || !\Elementor\Plugin::$instance->editor->is_edit_mode()) { | |
| 29 | 65 | return; |
| 30 | 66 | } |
| 31 | 67 | |
| 68 | + if (!$this->can_use_builder_widgets()) { | |
| 69 | + $this->render_pro_required_notice(); | |
| 70 | + return; | |
| 71 | + } | |
| 72 | + | |
| 73 | + // Check if we're editing a Checkout template | |
| 74 | + if (class_exists('King_Addons\\Woo_Builder\\Context') && Woo_Context::is_editing_template_type('checkout')) { | |
| 75 | + // Don't show notice - we're in the right template type | |
| 76 | + return; | |
| 77 | + } | |
| 78 | + | |
| 32 | 79 | echo '<div class="king-addons-woo-builder-notice">' . esc_html__('This widget works only on the WooCommerce checkout page.', 'king-addons') . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Editor-only upsell when the site cannot use Pro. | |
| 84 | + * | |
| 85 | + * @return void | |
| 86 | + */ | |
| 87 | + protected function render_pro_required_notice(): void | |
| 88 | + { | |
| 89 | + if (class_exists('King_Addons\\Core')) { | |
| 90 | + Core::renderEditorHint(esc_html__('Available in King Addons Pro.', 'king-addons')); | |
| 91 | + return; | |
| 92 | + } | |
| 93 | + | |
| 94 | + echo '<div class="king-addons-woo-builder-notice">' . esc_html__('Available in King Addons Pro.', 'king-addons') . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 33 | 95 | } |
| 34 | 96 | } |
| 35 | 97 | |
| 36 | 98 | |