Created
February 3, 2022 19:31
-
-
Save felipeelia/da5771375baa66eb8e36ccf05d68fbb3 to your computer and use it in GitHub Desktop.
Add compatibility between ElasticPress and WooCommerce Customer/Order/Coupon Export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add compatibility between ElasticPress and WooCommerce Customer/Order/Coupon Export. | |
*/ | |
add_filter( | |
'ep_sync_taxonomies', | |
function ( $taxonomies ) { | |
if ( class_exists( '\SkyVerge\WooCommerce\CSV_Export\Taxonomies_Handler' ) ) { | |
$taxonomies[] = \SkyVerge\WooCommerce\CSV_Export\Taxonomies_Handler::TAXONOMY_NAME_ORDERS; | |
} | |
return $taxonomies; | |
} | |
); | |
add_action( | |
'set_object_terms', | |
function ( $object_id, $terms, $tt_ids, $taxonomy ) { | |
if ( | |
! class_exists( '\SkyVerge\WooCommerce\CSV_Export\Taxonomies_Handler' ) || | |
! class_exists( '\ElasticPress\Indexables' ) || | |
$taxonomy !== \SkyVerge\WooCommerce\CSV_Export\Taxonomies_Handler::TAXONOMY_NAME_ORDERS | |
) { | |
return; | |
} | |
\ElasticPress\Indexables::factory()->get( 'post' )->index( $object_id, true ); | |
}, | |
10, | |
4 | |
); | |
add_action( | |
'deleted_term_relationships', | |
function ( $object_id, $tt_ids, $taxonomy ) { | |
if ( | |
! class_exists( '\SkyVerge\WooCommerce\CSV_Export\Taxonomies_Handler' ) || | |
! class_exists( '\ElasticPress\Indexables' ) || | |
$taxonomy !== \SkyVerge\WooCommerce\CSV_Export\Taxonomies_Handler::TAXONOMY_NAME_ORDERS | |
) { | |
return; | |
} | |
\ElasticPress\Indexables::factory()->get( 'post' )->index( $object_id, true ); | |
}, | |
10, | |
3 | |
); | |
add_action( | |
'pre_get_posts', | |
function ( $query ) { | |
if ( 'shop_order' === $query->get( 'post_type' ) && in_array( $query->get( 'post_status' ), [ 'any', 'all' ], true ) ) { | |
$query->set( 'post_status', array_keys( wc_get_order_statuses() ) ); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment