I'm validating the maximum number of products a user can buy per day.
I could limit the number of products by woocommerce_add_to_cart_validation and woocommerce_after_cart_item_quantity_update and it works fine.
the problem is when the user increases the quantity of a product without pressing the "recalculate the cart" button and after that press the "proceed to checkout" button, there will be no warning or error, I know the cart is not get updated but is there a way to show a warning to the user about the number of products in the cart, even when the user does not press recalculate button?
Update:
if the user is guest and login to site after placing his orders woocommerce_after_cart_item_quantity_update and woocommerce_add_to_cart_validation wont fire.
how can I check the quantity of products and redirect him to the cart page (if needed) and show an error before allowing him to enter the checkout page?
Related
This question comes in two parts:
Create a button that does the same as the woocommerce shortcode [add_to_cart] but without any plugins or shortcodes
Add a quantity field next to the add to cart button that allows the user to add a selected amount of products to their cart.
In essence, I want to circumnavigate the cart page, and have the customer add their product(s) on single pages.
So far, I am able to have a button that links the selected product to the cart page. The cart page is where a user is able to select the quantity of products to add, and add the products to the final checkout page. As stated above, I want to circumnavigate the cart page, and have the user be able to do the same functionality of the cart page, but on a regular page instead.
Here is my button that I have made for that purpose:
<form method="post">
<button class="Payment" name="asbestos_inspector_refresher">Register & Pay With Credit Card</button>
</form>
if(isset($_POST['asbestos_inspector_refresher']))
{
session_start();
$_SESSION['class_name'] = $class_name;
$_SESSION['product_name'] = $product_name;
wp_redirect("https://mwcti.com/Data_Table/?success=yes");
}
EDIT: Data_Table is a blank page before the cart page I made during testing to see if the value for the product would carry over to the cart page.
Working on a client's website which uses External products that link to an enquiry form further down on the page. I would like to add this product to the cart when the form is submitted.
I have tried just adding "?add-to-cart=[product-id]&quantity=1" to the end of the URL when the submit button is clicked, where [product-id] corresponds to the current product's ID but it just pops up with a message saying
"Sorry, this product cannot be purchased."
I just need the name of the product to be added to the cart with no price attached.
As clarification, the user will not be charged. It will send the order confirmation to the admin and customer, total price and payment will be arranged offline.
Any help would be massively appreciated.
basically I want to prevent users who are not logged in to not be able to add a product into the cart. When the customer is on the category page and clicks on "add to cart", the page should be refreshed with an error message "Login or Register [..].
I have already looked for some solutions in StackOverflow and could find a good solution using WooCommerce Avoid add to cart for non logged user
(I only use the second snippet, because I don't want to actually change the Interface/Design):
However, when AJAX is activated and the customer clicks on the add to cart (on the category page), the page doesn't refresh with the Error Message - but the customer will be directed to the actual Product Page and then(!) have to click on add to cart again in order to get the error message.
Is there any way to change the code or anything like that, so that clicking on the add to cart button on the category page as an unregistered/unlogged used will refresh the same page with an error message (and not redirect to the product page).
On my woocommerce single product pages I have added a duplicate “Add to cart” button,Now Two Add to cart button in single product page.if it was possible when someone clicks the first add to cart button and gets redirected to the checkout page that we could have the payment option of “First Payment Gateway” open as the default?Same as i want someone clicks the second add to cart button and gets redirected to the checkout page that we could have the payment option of “Second Payment Gateway” open as the default
You can override checkout.js and achieve this.
Have a look here: How To Prevent Woocommerce from selecting default payment method on Checkout page?
In woocommerce, I am trying to build a shopping page where user can select more than one product at a time.once the user selects the products then i am posting the productids from the page to the cart.php file of woocommerce.There , I have added products to cart using,
WC()->cart->add_to_cart($productid[$i]);
programmetically on the cart.php file of woocommerce plugin.
It correctly shows the products in the cart, but once I press "checkout", it redirects to the cart again, but this time, the cart is empty.
And further, if I login and do the same process, the checkout works correctly.