Skip to content

Instantly share code, notes, and snippets.

@nagygabor
Created October 24, 2018 18:44
Show Gist options
  • Save nagygabor/3879b4c937d2fe9dbde993ba2c29d822 to your computer and use it in GitHub Desktop.
Save nagygabor/3879b4c937d2fe9dbde993ba2c29d822 to your computer and use it in GitHub Desktop.
Ne adjon hozzá többet a cartba
//https://stackoverflow.com/questions/28576667/get-cart-item-name-quantity-all-details-woocommerce
function xnagyg_woocommerce_add_to_cart_validation($passed,$product_id,$quantity) {
//nem megy if (empty( $_GET['add-to-cart-only-once'] )){
// return true; //nincs az url-ben jel, hogy figyeljük
// }
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values)
{
if ($product_id == $values['product_id'] && $quantity <= $values['quantity'])
{
return false;//ne adjon még egyet hozzá
}
}
return true; //nincs benne annyi, adjon hozzá
}
add_action( 'woocommerce_add_to_cart_validation', 'xnagyg_woocommerce_add_to_cart_validation',10,3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment