Quantcast
Channel: WordPress.org Forums » [WooCommerce] Support
Viewing all articles
Browse latest Browse all 102134

Double-A-Ron on "[Plugin: WooCommerce - excelling eCommerce] Total number of items in cart"

$
0
0

Hi there, little bit of progress. First off I'm no coding expert as you'll see but this is what I've managed to hack together so far:

<?php

if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ){
foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->exists() && $values['quantity'] > 0 && $_product->get_attribute( 'pa_product-type' ) == "singleBottle" ) {

if ( $_product->is_sold_individually() ) {
$product_quantity = '1';
} else {
$product_quantity = sprintf( '<input name="cart[%s][qty]" data-min="%s" data-max="%s" value="%s"/>', $cart_item_key, $data_min, $data_max, esc_attr( $values['quantity'] ) );
}

echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key );

}
}
}

?>

This basically gives me form inputs with the correct pre-filled cart quantities of all the products that have an attribute of 'singleBottle'.

My next (and final) step which I'm really struggling with is how to get these quantities into a single array so I can total them up and use that figure as a variable to make the 'proceed to checkout' show/hide depending on the number of bottles in the cart.

Again, sorry if this code doesn't look too fantastic and offends anyone but it's the best I can do with my (very) limited coding skills.


Viewing all articles
Browse latest Browse all 102134

Trending Articles