Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subscriptions support #428

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions includes/Admin/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/Admin/ListTables/KeysTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) );
Expand Down
27 changes: 27 additions & 0 deletions src/Models/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down Expand Up @@ -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'.
Expand Down
9 changes: 9 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading