Skip to content

Instantly share code, notes, and snippets.

@AchalJ
Created May 4, 2024 14:07
Show Gist options
  • Save AchalJ/f389ef624d169caceebfba55f9dad27a to your computer and use it in GitHub Desktop.
Save AchalJ/f389ef624d169caceebfba55f9dad27a to your computer and use it in GitHub Desktop.
Vagonic Sortable compatibility with Content Grid AJAX pagination
<?php // <- ignore this line.
// Add Vagonic sort compatibility with Content Grid AJAX pagination.
add_action( 'woocommerce_product_query', function( $query, $wc_query ) {
if ( ! is_admin() && $query->is_main_query() && is_array( $_POST ) && isset( $_POST['current_tax'], $_POST['current_term'] ) ) {
$term = get_term_by( 'slug', wp_unslash( $_POST['current_term'] ), wp_unslash( $_POST['current_tax'] ) );
if ( $term && ! is_wp_error( $term ) ) {
$term_id = $term->term_id;
if ( $term->taxonomy == 'product_tag' ) {
$meta_key = '_vgnc_tag_menu_order_' . $term_id;
} elseif ( $term->taxonomy == 'product_cat' ){
$meta_key = '_vgnc_cat_menu_order_' . $term_id;
} else {
$meta_key = 'menu_order';
}
$query->set( 'meta_key', $meta_key );
}
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment