Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipeelia/da5771375baa66eb8e36ccf05d68fbb3 to your computer and use it in GitHub Desktop.
Save felipeelia/da5771375baa66eb8e36ccf05d68fbb3 to your computer and use it in GitHub Desktop.
Add compatibility between ElasticPress and WooCommerce Customer/Order/Coupon Export
<?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