I'm using a filter to remove the "first" and "last" classes from the product-grid.
When I set $classes to NULL it removes all of them, but my code should remove just the two. But that doesn't work.
add_filter( 'post_class', 'prefix_post_class', 21 );
function prefix_post_class( $classes ) {
if ( 'product' == get_post_type() ) {
$classes = array_diff( $classes, array( 'first', 'last' ) );
// $classes = NULL; <-- This works strangely enough
}
return $classes;
}
You can use the WooCommerce Post Class filter instead.
So you get:
/**
* WooCommerce Post Class filter.
*
* @since 3.6.2
* @param array $classes Array of CSS classes.
* @param WC_Product $product Product object.
*/
function filter_woocommerce_post_class( $classes, $product ) {
// array_values() returns all the values from the array and indexes the array numerically.
// array_diff - Compares array against one or more other arrays and returns the values in array that are not present in any of the other arrays.
$classes = array_values( array_diff( $classes, array( 'first', 'last' ) ) );
return $classes;
}
add_filter( 'woocommerce_post_class', 'filter_woocommerce_post_class', 10, 2 );