Created
October 24, 2018 18:44
-
-
Save nagygabor/3879b4c937d2fe9dbde993ba2c29d822 to your computer and use it in GitHub Desktop.
Ne adjon hozzá többet a cartba
This file contains 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
//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