WordPress.org

Support

Support » Plugins and Hacks » WooCommerce » Total number of items in cart

Total number of items in cart

  • Hi,

    What I’m looking to do is get the total number of items in the cart with a certain product attribute to stop people proceeding to checkout.

    So far I’ve managed to find out how to pull the total number of products in the cart and use this to hide the proceed to checkout button with the following code which works fine:

    $bottlesTotal = sprintf(_n(‘%d bottle’, ‘%d bottles’, $woocommerce->cart->cart_contents_count, ‘woothemes’), $woocommerce->cart->cart_contents_count);

    But I now need to work out how to pull the total for items in the cart with the attribute of ‘singleBottle’ , this is the part which has got me totally stumped.

    Any help would be greatly appreciated ………. Aaron

    http://wordpress.org/extend/plugins/woocommerce/

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

    Hi Double,
    I think this plugin might do the trick: http://wordpress.org/extend/plugins/minimum-purchase-for-woocommerce/ . See what you think.

    Thanks for that Varktech.

    The pro version of your plugin was just what I was looking for. Managed to get me out of a pickle and meant I didn’t have to spend the weekend on the problem.

    Hey, glad that was what you needed. Cheers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Total number of items in cart’ is closed to new replies.
Skip to toolbar