Exclude checkout-draft orders from WC Admin reports and My Account > Orders (https://github.com/woocommerce/woocommerce-blocks/pull/3379)
* Exclude checkout-draft orders from WC Admin reports * Hook into order query args * Add comments before applying filters * Revert "Add comments before applying filters" This reverts commit 83b695665c05a3a9e7669e8777080c6ff10d8421. * Revert "Hook into order query args" This reverts commit 94cec6c83cf5b5ce05cd106daf217c0b08f13a03. * Hide draft orders from My Account > Orders * Move filter to its own file * Use custom plugin namespace for filter
This commit is contained in:
parent
e3163dc00d
commit
3f01676d16
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { addFilter } from '@wordpress/hooks';
|
||||
|
||||
addFilter(
|
||||
'woocommerce_admin_analytics_settings',
|
||||
'woocommerce-blocks/exclude-draft-status-from-analytics',
|
||||
( settings ) => {
|
||||
const removeCheckoutDraft = ( optionsGroup ) => {
|
||||
if ( optionsGroup.key === 'customStatuses' ) {
|
||||
return {
|
||||
...optionsGroup,
|
||||
options: optionsGroup.options.filter(
|
||||
( option ) => option.value !== 'checkout-draft'
|
||||
),
|
||||
};
|
||||
}
|
||||
return optionsGroup;
|
||||
};
|
||||
|
||||
const actionableStatusesOptions = settings.woocommerce_actionable_order_statuses.options.map(
|
||||
removeCheckoutDraft
|
||||
);
|
||||
const excludedStatusesOptions = settings.woocommerce_excluded_report_order_statuses.options.map(
|
||||
removeCheckoutDraft
|
||||
);
|
||||
|
||||
return {
|
||||
...settings,
|
||||
woocommerce_actionable_order_statuses: {
|
||||
...settings.woocommerce_actionable_order_statuses,
|
||||
options: actionableStatusesOptions,
|
||||
},
|
||||
woocommerce_excluded_report_order_statuses: {
|
||||
...settings.woocommerce_excluded_report_order_statuses,
|
||||
options: excludedStatusesOptions,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
|
@ -10,6 +10,7 @@ import { getSetting } from './get-setting';
|
|||
|
||||
export * from './default-constants';
|
||||
export { setSetting } from './set-setting';
|
||||
import './exclude-draft-status-from-analytics';
|
||||
|
||||
/**
|
||||
* Note: this attempts to coerce the wpVersion to a semver for comparison
|
||||
|
|
|
@ -40,8 +40,11 @@ class DraftOrders {
|
|||
if ( $this->package->feature()->is_feature_plugin_build() ) {
|
||||
add_filter( 'wc_order_statuses', [ $this, 'register_draft_order_status' ] );
|
||||
add_filter( 'woocommerce_register_shop_order_post_statuses', [ $this, 'register_draft_order_post_status' ] );
|
||||
add_filter( 'woocommerce_analytics_excluded_order_statuses', [ $this, 'append_draft_order_post_status' ] );
|
||||
add_filter( 'woocommerce_valid_order_statuses_for_payment', [ $this, 'append_draft_order_post_status' ] );
|
||||
add_filter( 'woocommerce_valid_order_statuses_for_payment_complete', [ $this, 'append_draft_order_post_status' ] );
|
||||
// Hook into the query to retrieve My Account orders so draft status is excluded.
|
||||
add_action( 'woocommerce_my_account_my_orders_query', [ $this, 'delete_draft_order_post_status_from_args' ] );
|
||||
add_action( 'woocommerce_cleanup_draft_orders', [ $this, 'delete_expired_draft_orders' ] );
|
||||
add_action( 'admin_init', [ $this, 'install' ] );
|
||||
} else {
|
||||
|
@ -130,6 +133,31 @@ class DraftOrders {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove draft status from the 'status' argument of an $args array.
|
||||
*
|
||||
* @param array $args Array of arguments containing statuses in the status key.
|
||||
* @internal
|
||||
* @return array
|
||||
*/
|
||||
public function delete_draft_order_post_status_from_args( $args ) {
|
||||
if ( ! array_key_exists( 'status', $args ) ) {
|
||||
$statuses = [];
|
||||
foreach ( wc_get_order_statuses() as $key => $label ) {
|
||||
if ( self::DB_STATUS !== $key ) {
|
||||
$statuses[] = str_replace( 'wc-', '', $key );
|
||||
}
|
||||
}
|
||||
$args['status'] = $statuses;
|
||||
} elseif ( self::DB_STATUS === $args['status'] ) {
|
||||
$args['status'] = '';
|
||||
} elseif ( is_array( $args['status'] ) ) {
|
||||
$args['status'] = array_diff_key( $args['status'], array( self::STATUS => null ) );
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append draft status to a list of statuses.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue