Merge pull request #2189 from GeertDD/post_class
Moving custom product classes to the post_class filter
This commit is contained in:
commit
766c6a7ef0
|
@ -30,10 +30,6 @@ $woocommerce_loop['loop']++;
|
|||
|
||||
// Extra post classes
|
||||
$classes = array();
|
||||
if ( $product->is_featured() )
|
||||
$classes[] = 'featured';
|
||||
if ( $product->is_on_sale() )
|
||||
$classes[] = 'sale';
|
||||
if ( 0 == ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 == $woocommerce_loop['columns'] )
|
||||
$classes[] = 'first';
|
||||
if ( 0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns'] )
|
||||
|
|
|
@ -10,15 +10,6 @@
|
|||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $product;
|
||||
|
||||
// Extra post classes
|
||||
$classes = array();
|
||||
if ( $product->is_featured() )
|
||||
$classes[] = 'featured';
|
||||
if ( $product->is_on_sale() )
|
||||
$classes[] = 'sale';
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
@ -30,7 +21,7 @@ if ( $product->is_on_sale() )
|
|||
do_action( 'woocommerce_before_single_product' );
|
||||
?>
|
||||
|
||||
<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class( $classes ); ?>>
|
||||
<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
|
||||
|
||||
<?php
|
||||
/**
|
||||
|
|
|
@ -471,6 +471,7 @@ class Woocommerce {
|
|||
add_action( 'wp_head', array( $this, 'generator' ) );
|
||||
add_action( 'wp_head', array( $this, 'wp_head' ) );
|
||||
add_filter( 'body_class', array( $this, 'output_body_class' ) );
|
||||
add_filter( 'post_class', array( $this, 'post_class' ), 20, 3 );
|
||||
add_action( 'wp_footer', array( $this, 'output_inline_js' ), 25 );
|
||||
|
||||
// HTTPS urls with SSL on
|
||||
|
@ -1903,6 +1904,32 @@ class Woocommerce {
|
|||
return $classes;
|
||||
}
|
||||
|
||||
/** Post Classes **********************************************************/
|
||||
|
||||
/**
|
||||
* Adds extra post classes for products
|
||||
*
|
||||
* @access public
|
||||
* @param array $classes
|
||||
* @param string|array $class
|
||||
* @param int $post_id
|
||||
* @return array
|
||||
*/
|
||||
public function post_class( $classes, $class, $post_id ) {
|
||||
$product = get_product( $post_id );
|
||||
|
||||
if ( $product ) {
|
||||
if ( $product->is_on_sale() ) {
|
||||
$classes[] = 'sale';
|
||||
}
|
||||
if ( $product->is_featured() ) {
|
||||
$classes[] = 'featured';
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/** Inline JavaScript Helper **********************************************/
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue