PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.44
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.44
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / helpers / Woo_Builder / Abstract_Single_Widget.php

Abstract_Single_Widget.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.44, at includes/helpers/Woo_Builder/Abstract_Single_Widget.php

64 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Base class for Single Product builder widgets.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Widget_Base;
11 use WC_Product;
12
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 /**
18 * Provides product resolution and editor notices.
19 */
20 abstract class Abstract_Single_Widget extends Widget_Base
21 {
22 /**
23 * Get current product object.
24 *
25 * @return WC_Product|null
26 */
27 protected function get_product(): ?WC_Product
28 {
29 global $product, $post;
30
31 if ($product instanceof WC_Product) {
32 return $product;
33 }
34
35 if (!empty($post->ID) && 'product' === get_post_type($post->ID)) {
36 $prod = wc_get_product($post->ID);
37 return $prod instanceof WC_Product ? $prod : null;
38 }
39
40 return null;
41 }
42
43 /**
44 * Render placeholder when product context is missing.
45 *
46 * @return void
47 */
48 protected function render_missing_product_notice(): void
49 {
50 if (!\Elementor\Plugin::$instance->editor->is_edit_mode()) {
51 return;
52 }
53
54 echo '<div class="king-addons-woo-builder-notice">' . esc_html__('This widget works only in a Single Product context.', 'king-addons') . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
55 }
56 }
57
58
59
60
61
62
63
64