From a9e3f20b2979986e533e8132b1a7d8931bf5bc96 Mon Sep 17 00:00:00 2001 From: kawsarahmedr Date: Thu, 15 Aug 2024 13:27:46 +0600 Subject: [PATCH 1/4] Add filter to the product data tabs --- includes/Admin/Products.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/Admin/Products.php b/includes/Admin/Products.php index 0b96933f..48c5b180 100644 --- a/includes/Admin/Products.php +++ b/includes/Admin/Products.php @@ -86,11 +86,14 @@ public static function print_style() { * @return mixed */ public static function product_data_tab( $tabs ) { - $tabs['wc_serial_numbers'] = array( - 'label' => __( 'Serial Numbers', 'wc-serial-numbers' ), - 'target' => 'wc_serial_numbers_data', - 'class' => array( 'show_if_simple' ), - 'priority' => 11, + $tabs['wc_serial_numbers'] = apply_filters( + 'wc_serial_numbers_product_data_tab', + array( + 'label' => __( 'Serial Numbers', 'wc-serial-numbers' ), + 'target' => 'wc_serial_numbers_data', + 'class' => array( 'show_if_simple', 'hide_if_subscription', 'hide_if_variable-subscription' ), + 'priority' => 11, + ) ); return $tabs; From 0ee7b4d3c2b73e2e438fd9cd75dc9eab047db515 Mon Sep 17 00:00:00 2001 From: kawsarahmedr Date: Thu, 15 Aug 2024 16:16:51 +0600 Subject: [PATCH 2/4] Add filter to the update keys fucntion --- src/functions.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/functions.php b/src/functions.php index 9f807365..2be7a36f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -541,6 +541,15 @@ function wcsn_order_update_keys( $order_id ) { continue; } + /** + * Filter hook to alter the keys before assigning them to the order item. + * + * @param Key[] $keys The keys. + * @param \WC_Order_Item $item Order item. + * @param \WC_Order $order Order object. + */ + $keys = apply_filters( 'wc_serial_numbers_order_item_keys', $keys, $item, $order ); + // Assign keys to order. foreach ( $keys as $key ) { $key->set_data( From 92ad68f3e1683a1d80d1087db50c15424022e803 Mon Sep 17 00:00:00 2001 From: kawsarahmedr Date: Thu, 15 Aug 2024 16:27:03 +0600 Subject: [PATCH 3/4] Add filter to the keys list table --- src/Admin/ListTables/KeysTable.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Admin/ListTables/KeysTable.php b/src/Admin/ListTables/KeysTable.php index 9ab8eaac..2484ae48 100644 --- a/src/Admin/ListTables/KeysTable.php +++ b/src/Admin/ListTables/KeysTable.php @@ -124,6 +124,15 @@ public function prepare_items() { 'search' => $search, ); + /** + * Filter the query arguments for the list table. + * + * @param array $args An associative array of arguments. + * + * @since 2.0.1 + */ + $args = apply_filters( 'wc_serial_numbers_keys_table_query_args', $args ); + $this->items = Key::query( $args ); $this->available_count = Key::count( array_merge( $args, array( 'status' => 'available' ) ) ); $this->pending_count = Key::count( array_merge( $args, array( 'status' => 'pending' ) ) ); From 1a9de93fa4635df5e3088aa74db1914b90415180 Mon Sep 17 00:00:00 2001 From: kawsarahmedr Date: Thu, 15 Aug 2024 17:36:09 +0600 Subject: [PATCH 4/4] Update key model --- src/Models/Key.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Models/Key.php b/src/Models/Key.php index 77c09881..e038127c 100644 --- a/src/Models/Key.php +++ b/src/Models/Key.php @@ -41,6 +41,7 @@ class Key extends Model { 'activation_count' => 0, 'order_id' => 0, 'vendor_id' => 0, + 'subscription_id' => 0, 'status' => 'available', 'validity' => 0, 'order_date' => '', @@ -330,6 +331,32 @@ public function set_vendor_id( $vendor_id ) { $this->set_prop( 'vendor_id', absint( $vendor_id ) ); } + /** + * Get the subscription id. + * + * @param string $context What the value is for. Valid values are 'view' and 'edit'. + * + * @since 1.4.6 + * + * @return int + */ + public function get_subscription_id( $context = 'edit' ) { + return $this->get_prop( 'subscription_id', $context ); + } + + /** + * Set the subscription id. + * + * @param int $subscription_id Subscription id. + * + * @since 2.0.1 + * + * @return void + */ + public function set_subscription_id( $subscription_id ) { + $this->set_prop( 'subscription_id', absint( $subscription_id ) ); + } + /** * Get the status. * Possible values: 'active', 'inactive', 'expired', 'cancelled', 'pending', 'failed', 'refunded', 'deleted'.