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

Allow search for several invoice numbers on Orders page #918

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 18 additions & 9 deletions includes/Compatibility/ThirdPartyPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ public function add_yith_product_bundles_classes( string $classes, ?string $docu
if ( empty( $order ) ) {
return $classes;
}

if ( ! $order instanceof \WC_Abstract_Order ) {
return $classes;
}

if ( empty( $item_id ) && ! empty( $classes ) ) {
$item_id = $this->get_item_id_from_classes( $classes );
}
Expand All @@ -226,7 +226,7 @@ public function add_yith_product_bundles_classes( string $classes, ?string $docu
} else {
return $classes;
}

$product = null;
$bundled_by = null;

Expand Down Expand Up @@ -378,7 +378,7 @@ function restore_wgm_thumbnails( $document_type, $document ) {
}

/**
* Adds invoice number filter to the search filters available in the admin order search.
* Adds "Invoice numbers" filter to the search filters available in the admin order search.
*
* @param array $options List of available filters.
*
Expand All @@ -388,24 +388,33 @@ function hpos_admin_search_filters( array $options ): array {
if ( WPO_WCPDF()->admin->invoice_number_search_enabled() ) {
$all = $options['all'];
unset( $options['all'] );
$options['invoice_number'] = __( 'Invoice number', 'woocommerce-pdf-invoices-packing-slips' );
$options['invoice_numbers'] = __( 'Invoice numbers', 'woocommerce-pdf-invoices-packing-slips' );
$options['all'] = $all;
}

return $options;
}

/**
* Modifies the arguments passed to `wc_get_orders()` to support 'invoice_number' order search filter.
* Modifies the arguments passed to `wc_get_orders()` to support 'invoice_numbers' order search filter.
*
* @param array $order_query_args Arguments to be passed to `wc_get_orders()`.
*
* @return array
*/
function invoice_number_query_args( array $order_query_args ): array {
if ( isset( $order_query_args['search_filter'] ) && 'invoice_number' === $order_query_args['search_filter'] && isset( $order_query_args['s'] ) ) {
$order_query_args['meta_key'] = '_wcpdf_invoice_number';
$order_query_args['meta_value'] = $order_query_args['s'];
if ( isset( $order_query_args['search_filter'] ) && 'invoice_numbers' === $order_query_args['search_filter'] && ! empty( $order_query_args['s'] ) ) {
$invoice_numbers = explode( ',', $order_query_args['s'] );
$invoice_numbers = array_map( function ( $number ) {
return sanitize_text_field( trim( $number ) );
}, $invoice_numbers );

$order_query_args['meta_query'] = $order_query_args['meta_query'] ?? array();
$order_query_args['meta_query'][] = [
'key' => '_wcpdf_invoice_number',
'value' => $invoice_numbers,
'compare' => 'IN',
];
$order_query_args['search_filter'] = 'all';
unset( $order_query_args['s'] );
}
Expand Down
Loading