PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.12.2
Independent Analytics – WordPress Analytics Plugin v2.12.2
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Ecommerce / WooCommerce_Referrer_Meta_Box.php
independent-analytics / IAWP / Ecommerce Last commit date
EDD_Order.php 1 year ago PMPro_Order.php 1 year ago SureCart_Event_Sync_Job.php 1 year ago SureCart_Order.php 1 year ago SureCart_Store.php 1 year ago WooCommerce_Order.php 1 year ago WooCommerce_Referrer_Meta_Box.php 1 year ago WooCommerce_Status_Manager.php 1 year ago
WooCommerce_Referrer_Meta_Box.php
112 lines
1 <?php
2
3 namespace IAWP\Ecommerce;
4
5 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
6 use IAWP\Illuminate_Builder;
7 use IAWP\Models\Campaign;
8 use IAWP\Models\Referrer;
9 use IAWP\Query;
10 use IAWP\Utils\Security;
11 use IAWPSCOPED\Illuminate\Database\Query\JoinClause;
12 /** @internal */
13 class WooCommerce_Referrer_Meta_Box
14 {
15 private $referrer;
16 private $campaign;
17 public function __construct()
18 {
19 \add_action('add_meta_boxes', [$this, 'maybe_add_meta_box'], 10, 2);
20 }
21 public function maybe_add_meta_box($post_type, $post_or_order_object) : void
22 {
23 if (!\IAWPSCOPED\iawp()->is_woocommerce_support_enabled()) {
24 return;
25 }
26 $order = $post_or_order_object instanceof \WP_Post ? wc_get_order($post_or_order_object->ID) : $post_or_order_object;
27 if ($order === \false) {
28 return;
29 }
30 $woocommerce_screen = \class_exists('\\Automattic\\WooCommerce\\Internal\\DataStores\\Orders\\CustomOrdersTableController') && wc_get_container()->get(CustomOrdersTableController::class)->custom_orders_table_usage_is_enabled() ? wc_get_page_screen_id('shop-order') : 'shop_order';
31 $current_screen = \get_current_screen();
32 if (\is_null($current_screen) || $current_screen->id !== $woocommerce_screen) {
33 return;
34 }
35 $referrer_row = $this->get_referrer_for($order->get_id());
36 $this->referrer = \is_object($referrer_row) ? new Referrer($referrer_row) : null;
37 $campaign_row = $this->get_campaign_for($order->get_id());
38 $this->campaign = \is_object($campaign_row) ? new Campaign($campaign_row) : null;
39 if (\is_null($this->referrer) && \is_null($this->campaign)) {
40 return;
41 }
42 \add_meta_box('iawp-wc-referrer-source', \esc_html__('Order Referrer', 'independent-analytics'), [$this, 'render_meta_box_content'], $woocommerce_screen, 'side');
43 }
44 public function render_meta_box_content($post_or_order_object) : void
45 {
46 $order = $post_or_order_object instanceof \WP_Post ? wc_get_order($post_or_order_object->ID) : $post_or_order_object;
47 if (!\is_null($this->referrer)) {
48 if ($this->referrer->has_link()) {
49 $content = '<a target="_blank" href="' . \esc_url($this->referrer->referrer_url()) . '">' . Security::string($this->referrer->referrer()) . '</a>';
50 } else {
51 $content = Security::string($this->referrer->referrer());
52 }
53 echo '<p><strong>' . \esc_html__('Referrer:', 'independent-analytics') . '</strong> <span data-testid="referrer">' . $content . '</span> <a class="info-link"
54 href="https://independentwp.com/knowledgebase/woocommerce/order-referrers-box/"
55 target="_blank"
56 style="text-decoration:none;float:right;">
57 <span class="dashicons dashicons-editor-help"></span>
58 </a>
59 </p>';
60 }
61 if (!\is_null($this->campaign)) {
62 if (\is_string($this->campaign->utm_source())) {
63 echo '<p><strong>' . \__('Campaign Source', 'independent-analytics') . ':</strong> <span data-testid="source">' . Security::string($this->campaign->utm_source()) . '</span> </p>';
64 }
65 if (\is_string($this->campaign->utm_medium())) {
66 echo '<p><strong>' . \__('Campaign Medium', 'independent-analytics') . ':</strong> <span data-testid="medium">' . Security::string($this->campaign->utm_medium()) . '</span> </p>';
67 }
68 if (\is_string($this->campaign->utm_campaign())) {
69 echo '<p><strong>' . \__('Campaign Name', 'independent-analytics') . ':</strong> <span data-testid="campaign">' . Security::string($this->campaign->utm_campaign()) . '</span> </p>';
70 }
71 if (\is_string($this->campaign->utm_term())) {
72 echo '<p><strong>' . \__('Campaign Term', 'independent-analytics') . ':</strong> <span data-testid="term">' . Security::string($this->campaign->utm_term()) . '</span> </p>';
73 }
74 if (\is_string($this->campaign->utm_content())) {
75 echo '<p><strong>' . \__('Campaign Content', 'independent-analytics') . ':</strong> <span data-testid="content">' . Security::string($this->campaign->utm_content()) . '</span> </p>';
76 }
77 }
78 }
79 private function get_campaign_for($order_id) : ?object
80 {
81 $orders_table = Query::get_table_name(Query::ORDERS);
82 $campaigns_table = Query::get_table_name(Query::CAMPAIGNS);
83 $views_table = Query::get_table_name(Query::VIEWS);
84 $sessions_table = Query::get_table_name(Query::SESSIONS);
85 $campaign_query = Illuminate_Builder::new()->select("landing_page_title AS title", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content")->from($orders_table, 'orders')->join("{$views_table} AS views", function (JoinClause $join) {
86 $join->on('views.id', '=', 'orders.view_id');
87 })->join("{$sessions_table} AS sessions", function (JoinClause $join) {
88 $join->on('sessions.session_id', '=', 'views.session_id');
89 })->join("{$campaigns_table} AS campaigns", function (JoinClause $join) {
90 $join->on('sessions.campaign_id', '=', 'campaigns.campaign_id');
91 })->where('orders.woocommerce_order_id', '=', $order_id);
92 $record = $campaign_query->get()->first();
93 return $record;
94 }
95 private function get_referrer_for($order_id) : ?object
96 {
97 $orders_table = Query::get_table_name(Query::ORDERS);
98 $views_table = Query::get_table_name(Query::VIEWS);
99 $sessions_table = Query::get_table_name(Query::SESSIONS);
100 $referrer_table = Query::get_table_name(Query::REFERRERS);
101 $referrer_query = Illuminate_Builder::new()->select('sessions.referrer_id', 'referrer', 'type AS referrer_type', 'domain')->from($orders_table, 'orders')->join("{$views_table} AS views", function (JoinClause $join) {
102 $join->on('views.id', '=', 'orders.view_id');
103 })->join("{$sessions_table} AS sessions", function (JoinClause $join) {
104 $join->on('sessions.session_id', '=', 'views.session_id');
105 })->join("{$referrer_table} AS referrers", function (JoinClause $join) {
106 $join->on('referrers.id', '=', 'sessions.referrer_id');
107 })->where('orders.woocommerce_order_id', '=', $order_id);
108 $record = $referrer_query->get()->first();
109 return $record;
110 }
111 }
112