WooCommerce Allow Checkout in Multiples Only not working for WooCommerce 2.3.5
-
Hi There, could some please help.
The code below no longer works for WooCommerce version 2.3.5 does any body know what needs to be changed?<?php
// check that cart items quantities totals are in multiples of 6
addaction( ‘woocommercecheckcartitems’, ‘woocommercecheckcartquantities’ );
function woocommercecheckcartquantities() {
global $woocommerce;
$multiples = 6;
$totalproducts = 0;
foreach ( $woocommerce->cart->getcart() as $cartitemkey => $values ) {
$totalproducts += $values[‘quantity’];
}
if ( ( $totalproducts % $multiples ) > 0 )
$woocommerce->adderror( sprintf( _(‘You need to buy in quantities of %s products’, ‘woocommerce’), $multiples ) );
}
// Limit cart items with a certain shipping class to be purchased in multiple only
addaction( ‘woocommercecheckcartitems’, ‘woocommercecheckcartquantitiesforclass’ );
function woocommercecheckcartquantitiesforclass() {
global $woocommerce;
$multiples = 6;
$class = ‘bottle’;
$totalproducts = 0;
foreach ( $woocommerce->cart->getcart() as $cartitemkey => $values ) {
$product = getproduct( $values[‘productid’] );
if ( $product->getshippingclass() == $class ) {
$totalproducts += $values[‘quantity’];
}
}
if ( ( $totalproducts % $multiples ) > 0 )
$woocommerce->adderror( sprintf( _(‘You need to purchase bottles in quantities of %s’, ‘woocommerce’), $multiples ) );
}
?>Thanks
- The topic ‘WooCommerce Allow Checkout in Multiples Only not working for WooCommerce 2.3.5’ is closed to new replies.