PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / classes / class-merchant-general-hooks.php

class-merchant-general-hooks.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.2, at inc/classes/class-merchant-general-hooks.php

171 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Merchant_Option Class.
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly
8 }
9
10 if ( ! class_exists( 'Merchant_General_Hooks' ) ) {
11 class Merchant_General_Hooks {
12
13 /**
14 * The single class instance.
15 */
16 private static $instance = null;
17
18 /**
19 * Instance.
20 */
21 public static function instance() {
22 if ( is_null( self::$instance ) ) {
23 self::$instance = new self();
24 }
25
26 return self::$instance;
27 }
28
29 /**
30 * Constructor.
31 */
32 private function __construct() {
33 }
34
35 /**
36 * Attach functions to WordPress
37 *
38 * @return void
39 */
40 public function load_hooks() {
41 add_action( 'init', array( $this, 'register_weekly_schedule' ) );
42 add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'hidden_order_item_meta' ) );
43 add_filter( 'woocommerce_order_item_get_formatted_meta_data', array( $this, 'strip_customer_facing_meta' ) );
44 }
45
46 /**
47 * Hide Merchant internal order item meta on the admin order screen.
48 *
49 * @param array $hidden Keys WooCommerce already hides.
50 *
51 * @return array
52 */
53 public function hidden_order_item_meta( $hidden ) {
54 /**
55 * Filter the hidden Merchant order item meta keys.
56 *
57 * @param array $keys Meta keys to hide.
58 *
59 * @since 2.3.2
60 */
61 $keys = apply_filters( 'merchant_hidden_order_item_meta', $this->order_item_meta_keys() );
62
63 return array_merge( (array) $hidden, $keys );
64 }
65
66 /**
67 * Drop non-underscore keys from the order details page and emails.
68 *
69 * @param object[]|mixed $formatted_meta Formatted meta objects keyed by meta id.
70 *
71 * @return object[]|mixed
72 */
73 public function strip_customer_facing_meta( $formatted_meta ) {
74 if ( ! is_array( $formatted_meta ) ) {
75 return $formatted_meta;
76 }
77
78 foreach ( $formatted_meta as $id => $meta ) {
79 if ( in_array( $meta->key, $this->customer_facing_meta_keys(), true ) ) {
80 unset( $formatted_meta[ $id ] );
81 }
82 }
83
84 return $formatted_meta;
85 }
86
87 /**
88 * Free and Pro order item meta keys. Listed here so they stay hidden even with Pro off.
89 *
90 * @return array
91 */
92 private function order_item_meta_keys() {
93 return array_merge(
94 array(
95 // pre-orders
96 '_merchant_pre_order',
97 '_merchant_is_pre_order_product',
98 '_merchant_pre_order_shipping_date',
99 '_pre_order_add_to_cart_event_id',
100
101 // product-bundles
102 '_mppb_parent_id',
103 '_mppb_ids',
104 '_mppb_price',
105 '_mppb_analytics_id',
106
107 // buy-x-get-y
108 '_merchant_bogo_offer_key',
109 '_merchant_bogo_analytics_id',
110
111 // analytics event ids
112 '_fbt_analytics_id',
113 '_cp_analytics_id',
114 '_recently_viewed_add_to_cart_event_id',
115 '_sticky_add_to_cart_event_id',
116 '_storewide_sale_analytics_id',
117 '_volume_discounts_analytics_id',
118 '_waitlist_back_in_stock_event_id',
119
120 // advanced-reviews
121 '_merchant_review_status',
122 '_merchant_review_images_added',
123
124 // delivery-pickup
125 '_merchant_delivery_pickup_group',
126 ),
127 $this->customer_facing_meta_keys()
128 );
129 }
130
131 /**
132 * Non-underscore keys that also leak on the order details page and emails.
133 *
134 * @return array
135 */
136 private function customer_facing_meta_keys() {
137 return array(
138 // thankyou-offers
139 'merchant_added_via',
140 'merchant_module_id',
141
142 // product-bundles (legacy)
143 'mppb_parent_id',
144 'mppb_ids',
145 'mppb_price',
146 );
147 }
148
149 /**
150 * Register weekly schedule.
151 *
152 * @return void
153 */
154 public function register_weekly_schedule() {
155 if ( function_exists( 'as_schedule_recurring_action' ) ) {
156 if ( ! as_next_scheduled_action( 'merchant_weekly_schedule' ) ) {
157 as_schedule_recurring_action( time(), WEEK_IN_SECONDS, 'merchant_weekly_schedule' );
158 }
159
160 return;
161 }
162
163 if ( ! wp_next_scheduled( 'merchant_weekly_schedule' ) ) {
164 wp_schedule_event( time(), 'weekly', 'merchant_weekly_schedule' );
165 }
166 }
167 }
168 }
169
170 $merchant_general_hooks = Merchant_General_Hooks::instance();
171 $merchant_general_hooks->load_hooks();