Created
March 3, 2016 08:38
-
-
Save yratof/f7c1655a4fa697a056b8 to your computer and use it in GitHub Desktop.
Woocommerce min-cart that shows a limit of 3 out of X products
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 | |
/* | |
Woocommerce cart that shows upto 3 | |
*/ | |
$visible_item_count = 0; | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | |
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); | |
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) { ?> | |
<div class="row"> | |
<div class="img-holder"> | |
<?php // Product Thumbail | |
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); | |
if ( ! $_product->is_visible() ) { echo $thumbnail; } | |
else { printf( '<a href="%s">%s</a>', esc_url( $_product->get_permalink( $cart_item ) ), $thumbnail ); } | |
?> | |
</div> | |
<div class="item-info"> | |
<h2> | |
<?php if ( ! $_product->is_visible() ) { echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . ' '; } | |
else { echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $_product->get_permalink( $cart_item ) ), $_product->get_title() ), $cart_item, $cart_item_key ); }?> | |
</h2> | |
<p><?php /* Meta data */ echo WC()->cart->get_item_data( $cart_item ); ?></p> | |
</div> | |
<div class="quantity"> | |
<?php | |
if ( $_product->is_sold_individually() ) { | |
$product_quantity = sprintf( '1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key ); | |
} else { | |
$product_quantity = woocommerce_quantity_input( array( | |
'input_name' => "cart[{$cart_item_key}][qty]", | |
'input_value' => $cart_item['quantity'], | |
'max_value' => $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(), | |
'min_value' => '0' | |
), $_product, false ); | |
} | |
echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item ); | |
?> | |
</div> | |
<span class="price"> | |
<?php echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); ?> | |
</span> | |
</div> | |
<?php } | |
// Only show 3 items | |
if ( ++$visible_item_count > 2 ) | |
break; | |
} | |
?> | |
<script> | |
jQuery( function( $ ) { | |
$( '.counted' ).html( ' <?php echo $visible_item_count; ?> /'); | |
} ); | |
</script> |
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
<div class="drop"> | |
<form action="#" class="cart-form"> | |
<div class="title"> | |
<h2><?php _e( 'Viewing', 'drivigital' ); ?><mark><span class="counted"></span><?php echo WC()->cart->cart_contents_count; ?></mark> <?php _e( 'goods', 'drivigital' );?></h2> | |
</div> | |
<div class="inner-area"> | |
<?php get_template_part( 'includes/_header', 'cart' ); ?> | |
</div> | |
<div class="sub-total"> | |
<div class="text-holder"> | |
<h2><?php _e( 'Sub total', 'drivigital' ) ?>:</h2> | |
<p><?php _e( 'Prices including VAT. excl. shipping', 'drivigital' ); ?></p> | |
</div> | |
<div class="total-price"><?php wc_cart_totals_subtotal_html(); ?></div> | |
</div> | |
<ul class="btn-box"> | |
<li> | |
<a href="#" class="btn see-cart"><?php _e( 'See your shopping cart', 'drivigital' ); ?></a> | |
</li> | |
<li> | |
<a href="#" class="btn checkout"><?php _e( 'To cart', 'drivigital' ); ?></a> | |
</li> | |
</ul> | |
</form> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment