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

Adds support for searching shop_subscriptions #2867 #3029

Merged
merged 4 commits into from
Nov 9, 2022
Merged
Changes from 2 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
118 changes: 105 additions & 13 deletions includes/classes/Feature/WooCommerce/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,22 @@ public function whitelist_taxonomies( $taxonomies, $post ) {
public function disallow_duplicated_query( $value, $query ) {
global $pagenow;

$searchable_post_types = array( 'shop_order' );

/**
* Expands or contracts the types of admin EP permits for WooCommerce.
*
* @hook ep_woocommerce_admin_searchable_post_types
* @since 4.4.0
* @param {array} $post_types Post types
* @return {array} New post types
*/
$searchable_post_types = apply_filters( 'ep_woocommerce_admin_searchable_post_types', $searchable_post_types );
ecaron marked this conversation as resolved.
Show resolved Hide resolved

/**
* Make sure we're on edit.php in admin dashboard.
*/
if ( 'edit.php' !== $pagenow || ! is_admin() || 'shop_order' !== $query->get( 'post_type' ) ) {
if ( 'edit.php' !== $pagenow || ! is_admin() || ! in_array( $query->get( 'post_type' ), $searchable_post_types, true ) ) {
return $value;
}

Expand Down Expand Up @@ -306,13 +318,25 @@ public function translate_args( $query ) {
$post_type = $query->get( 'post_type', false );

// Act only on a defined subset of all indexable post types here
$post_types = array(
'product',
'shop_order',
'shop_order_refund',
'product_variation',
);

/**
* Expands or contracts the post_types eligible for indexing..
*
* @hook ep_default_supported_post_types
* @since 4.4.0
* @param {array} $post_types Post types
* @return {array} New post types
*/
$supported_post_types = apply_filters( 'ep_default_supported_post_types', $post_types );
ecaron marked this conversation as resolved.
Show resolved Hide resolved

$supported_post_types = array_intersect(
array(
'product',
'shop_order',
'shop_order_refund',
'product_variation',
),
$supported_post_types,
Indexables::factory()->get( 'post' )->get_indexable_post_types()
);

Expand Down Expand Up @@ -391,7 +415,19 @@ public function translate_args( $query ) {

if ( ! empty( $s ) ) {
// Search query
if ( 'shop_order' === $post_type ) {
$searchable_post_types = array( 'shop_order' );

/**
* Expands or contracts the types of admin searches EP permits for WooCommerce.
*
* @hook ep_woocommerce_admin_searchable_post_types
* @since 4.4.0
* @param {array} $post_types Post types
* @return {array} New post types
*/
$searchable_post_types = apply_filters( 'ep_woocommerce_admin_searchable_post_types', $searchable_post_types );

if ( in_array( $post_type, $searchable_post_types, true ) ) {
$default_search_fields = array( 'post_title', 'post_content', 'post_excerpt' );
if ( ctype_digit( $s ) ) {
$default_search_fields[] = 'ID';
Expand Down Expand Up @@ -604,7 +640,19 @@ public function blacklist_coupons( $enabled, $query ) {
* @return bool
*/
public function bypass_order_permissions_check( $override, $post_id ) {
if ( 'shop_order' === get_post_type( $post_id ) ) {
$searchable_post_types = array( 'shop_order' );

/**
* Expands or contracts the types of admin EP permits for WooCommerce.
*
* @hook ep_woocommerce_admin_searchable_post_types
* @since 4.4.0
* @param {array} $post_types Post types
* @return {array} New post types
*/
$searchable_post_types = apply_filters( 'ep_woocommerce_admin_searchable_post_types', $searchable_post_types );

if ( in_array( get_post_type( $post_id ), $searchable_post_types, true ) ) {
return true;
}

Expand All @@ -622,12 +670,19 @@ public function bypass_order_permissions_check( $override, $post_id ) {
* @param \WP_Query $query Current query
*/
public function maybe_hook_woocommerce_search_fields( $query ) {
global $pagenow, $wp, $wc_list_table;
global $pagenow, $wp, $wc_list_table, $wp_filter;

if ( ! $this->should_integrate_with_query( $query ) ) {
return;
}

/**
* Determines actions to be applied, or removed, if doing a WooCommerce serarch
*
* @hook ep_woocommerce_hook_search_fields
*/
do_action( 'ep_woocommerce_hook_search_fields' );
ecaron marked this conversation as resolved.
Show resolved Hide resolved

if ( 'edit.php' !== $pagenow || empty( $wp->query_vars['s'] ) || 'shop_order' !== $wp->query_vars['post_type'] || ! isset( $_GET['s'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return;
}
Expand All @@ -651,7 +706,20 @@ public function search_order( $wp ) {
}

global $pagenow;
if ( 'edit.php' !== $pagenow || empty( $wp->query_vars['post_type'] ) || 'shop_order' !== $wp->query_vars['post_type'] ||

$searchable_post_types = array( 'shop_order' );

/**
* Expands or contracts the types of admin EP permits for WooCommerce.
*
* @hook ep_woocommerce_admin_searchable_post_types
* @since 4.4.0
* @param {array} $post_types Post types
* @return {array} New post types
*/
$searchable_post_types = apply_filters( 'ep_woocommerce_admin_searchable_post_types', $searchable_post_types );

if ( 'edit.php' !== $pagenow || empty( $wp->query_vars['post_type'] ) || ! in_array( $wp->query_vars['post_type'], $searchable_post_types, true ) ||
( empty( $wp->query_vars['s'] ) && empty( $wp->query_vars['shop_order_search'] ) ) ) {
return;
}
Expand All @@ -676,8 +744,20 @@ public function search_order( $wp ) {
* @return array
*/
public function add_order_items_search( $post_args, $post_id ) {
$searchable_post_types = array( 'shop_order' );

/**
* Expands or contracts the types of admin EP permits for WooCommerce.
*
* @hook ep_woocommerce_admin_searchable_post_types
* @since 4.4.0
* @param {array} $post_types Post types
* @return {array} New post types
*/
$searchable_post_types = apply_filters( 'ep_woocommerce_admin_searchable_post_types', $searchable_post_types );

// Make sure it is only WooCommerce orders we touch.
if ( 'shop_order' !== $post_args['post_type'] ) {
if ( ! in_array( $post_args['post_type'], $searchable_post_types, true ) ) {
return $post_args;
}

Expand Down Expand Up @@ -947,7 +1027,19 @@ public function price_filter( $args, $query_args, $query ) {
* @return bool
*/
public function keep_order_fields( $skip, $post_args ) {
if ( 'shop_order' === $post_args['post_type'] ) {
$searchable_post_types = array( 'shop_order' );

/**
* Expands or contracts the types of admin EP permits for WooCommerce.
*
* @hook ep_woocommerce_admin_searchable_post_types
* @since 4.4.0
* @param {array} $post_types Post types
* @return {array} New post types
*/
$searchable_post_types = apply_filters( 'ep_woocommerce_admin_searchable_post_types', $searchable_post_types );

if ( in_array( $post_args['post_type'], $searchable_post_types, true ) ) {
return true;
}

Expand Down