| 1 |
<?php |
| 2 |
/** |
| 3 |
* Base class for Checkout builder widgets. |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace King_Addons; |
| 9 |
|
| 10 |
use Elementor\Widget_Base; |
| 11 |
use King_Addons\Woo_Builder\Context as Woo_Context; |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Provides checkout context utilities. |
| 19 |
*/ |
| 20 |
abstract class Abstract_Checkout_Widget extends Widget_Base |
| 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 |
// In editor mode editing checkout template |
| 31 |
if (class_exists('King_Addons\\Woo_Builder\\Context') && Woo_Context::is_editing_template_type('checkout')) { |
| 32 |
return true; |
| 33 |
} |
| 34 |
|
| 35 |
// On actual checkout page |
| 36 |
if (function_exists('is_checkout') && is_checkout() && !is_order_received_page()) { |
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
return false; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Render placeholder when checkout context is missing. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
protected function render_missing_checkout_notice(): void |
| 49 |
{ |
| 50 |
if (!class_exists('\Elementor\Plugin') || !\Elementor\Plugin::$instance->editor->is_edit_mode()) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
// Check if we're editing a Checkout template |
| 55 |
if (class_exists('King_Addons\\Woo_Builder\\Context') && Woo_Context::is_editing_template_type('checkout')) { |
| 56 |
// Don't show notice - we're in the right template type |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
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 |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|