-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WC Ajax Mini Cart Quantity Buttons #703
Conversation
Hi Anisur, thank you, we are on a good way! mini-cart.php1. Check if product is only 1 in stock left or sold individuallyIt should be checked if products are out of stock or sold individually. Please add this 3 products to the cart:
After adding these products, go to cart page. Quantity for "Beanie" and "Hoodie with pocket" should be disabled. WooCommerce uses following code to check this in cart.php: if ( $_product->is_sold_individually() ) {
$min_quantity = 1;
$max_quantity = 1;
} else {
$min_quantity = 0;
$max_quantity = $_product->get_max_purchase_quantity();
} 2. If possible adding the quantity by a hook instead adding them direct to the templateSomething like this in ajax-add-to-cart.php: add_filter('woocommerce_widget_cart_item_quantity', 'add_minicart_quantity_fields', 10, 3);
function add_minicart_quantity_fields($html, $cart_item, $cart_item_key) {
$product_price = apply_filters('woocommerce_cart_item_price', WC()->cart->get_product_price($cart_item['data']), $cart_item, $cart_item_key);
return woocommerce_quantity_input(array('input_value' => $cart_item['quantity']), $cart_item['data'], false) . $product_price;
} This is important if user disables the entire ajax-add-to-cart.php in child by function: // Disable AJAX Cart
function register_ajax_cart() {
}
add_action('after_setup_theme', 'register_ajax_cart'); The reason for that is that quantity should not appear in mini-cart if user disabled the the file. woocommerce.jsAll additioinal code should be placed within a function in ajax-add-to-cart.php as well. Code should not load if users disables ajax-add-to-cart.php. In conclusion everything what is is related to ajax functionality should be placed in ajax-add-to-cart.php, to simply disable it in one single file. wc-minicart.php and wc-qty-btn.php looks good to me! Thanks in advance |
Hi Anisur, yes! Just two tiny things:
Last thing: Is it possible for you to update your fork, open a new PR and commit to https://github.com/bootscore/bootscore/tree/v6.0.0-beta1 branch? That's because many things happen since you started here and this will allow me to merge without asking for a review. This is not a must have, but will make things happen much more faster. Thank you! |
…c-ajax-mini-cart
…tscore into wc-ajax-mini-cart
This PR can be changed to merge into the v6 branch instead of the main branch. On GitHub when you edit the whole PR, and probably via git commands too. |
@justinkruit Got it |
Hi Anisur, closed to be perfect. Requesting only one more fix. If I change the amount manually in the input, not pressing the buttons, then data gets not updated anymore.
This was working fine until your second commit https://github.com/anisur2805/bootscore/tree/dfe1ecefcc9e80484d5a47b2971c6b1e951ba69f. The rest works like a charme :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Added the Ajax functionality for adding products to cart.
Closes #631