Created
April 1, 2015 20:16
-
-
Save dsmy/7a896f98e11abf047ad5 to your computer and use it in GitHub Desktop.
Custom Class if Item is in Cart Woocommerce
This file contains hidden or 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 | |
global $woocommerce; | |
// Extra post classes | |
$classes = array(); | |
if ( 0 == ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 == $woocommerce_loop['columns'] ) | |
$classes[] = 'first'; | |
if ( 0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns'] ) | |
$classes[] = 'last'; | |
// If item is in cart add this class | |
foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) { | |
$_product = $values['data']; | |
if( get_the_ID() == $_product->id ) { | |
$classes[] = 'in-cart'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment