Confirmation message before removing a product from cart - php

I just notice that in WooCommerce if customer removes a product from cart, there is no warning message or confirmation before deleting it.
Is there any ways to make a confirmation before removing a product from cart?
Thanks.

If you look at WC_Cart remove_cart_item() method source code here you will see on line 1015 that you can only use woocommerce_remove_cart_item action hook that is triggered before an item is removed from cart.
As removing an item is ajax driven in cart page, to do what you are expecting is certainly possible, but something really complicated.
Remember that on cart page, you already got a notice when you remove a cart items, that allow you to restore it… So adding a confirmation notice, is not really viable and even disturbing for customer experience.

Related

Woocommerce doesn't redirect to checkout page

its me again, i will give you guys a quick rundown of what i'm doing (i'm passing the cart info from one woocommerce store to another woocommerce store) i was finally able to send the product_id and quantity from the store A to the store B and in this one i'm using the woocommerce WC()->cart functions to create a copy of the cart in this last store so the client cant process his purchase, and its working well.
Here is the code.
$incoming_cart=unserialize(base64_decode($_POST["p_cart_t"]));
foreach ( $incoming_cart as $cart_item_key => $cart_item ) {
$product_id=$cart_item['product_id'];
$quantity_pro=$cart_item['quantity'];
print_r($product_id);
print_r($quantity_pro);
WC()->cart->empty_cart();
WC()->cart->add_to_cart($product_id,$quantity_pro);
}
My problem is, when i press checkout the system sends me to the cart page again like just refresh and the cart info gets lost.
I have to say that i'm passing the info of the cart that comes from store A to the cart-empty.php file from the store B cause since im switching between stores there is no cart in the store B and it says that the cart is empty, so what i did was paste the cart.php code into cart-empty.php and its working, the file is catching the info and mirroring the cart but i have this problem with the checkout.
¿do someone may know what this is happening?
¿what can i do to fix this?
I can sense a logic of execution problem here.
One question is where and when are you firing that code you provided. I would suggest, fire it on woocommerce_loaded hook. Then after adding everything to cart, redirect to cart page.
WooCommerce has an option that after adding a product to cart, you will be redirected to cart. I suggest you look for that.
Also, I can't help myself noticing that your code is emptying the cart in every loop. I would transfer WC()->cart->empty_cart(); outside foreach loop. Maybe after checking $incoming_cart is non empty, empty your cart, then run a loop to add all the products from $incoming_cart. Then redirect the page to the cart page. By this time the cart is not empty.
With this, you don't have to edit files from WooCommerce. Forget editing cart-empty.php

Magento add flash message for move from wishlist to cart

I'm trying to add a flash message upon moving of an individual item from a wishlist to the cart in Magento. This already happens when all items are added to cart, but not when an individual item is moved from the wishlist to the cart. Any help on this would be much appreciated.
Thanks.
EDIT: To clarify, this is something I want to add for when a single item is added from wishlist to cart. When you click the "Add all to cart" from the wishlist, it does give you a message, but it does not give this message when just one item is individually added to cart from the wishlist.
Are you using Magento Enterprise?
I checked the code base and it looks like they are already showing a message for moving a single item from wishlist to cart.
app/code/core/Enterprise/Wishlist/controllers/SearchController.php:260

Adding cart error to prevent going into the checkout

i have been working trying to create an edit order system where when an order is bellow a given state the customer can edit the order
now i have everything working by adding a reorder like link which does the exact same as reorder but creates a session which identifies that your editing an order, in order to do this for out of stock products i had to turn backorders on
however i have found a glitch, if a customer was to add 5 hats to the cart and logs off, if when they come back the item's stock qty is now 0 they can still go into the cart, naturally this is because of the backorders being enabled.
i have made a CartController to pick up adding/updates to the shopping cart and manually check if the stock is less than what's in the cart, however if the customer had the item when there was ample stock, leave and returns when it's now out of stock, they bypass these checks
one suggestion that was made by a college was that we shorten the lifetime of the cart session for registered customers, while we could do this, there is more of a problem during a sale
originally, before backorders was turned on, if this same situation occurred the "Proceed to checkout" button would be missing and you would get an error message
now i've tried fixing up a new IndexController and using $this->_getSession()->addError('Some products in your cart have gone out of stock'); but i'm not getting the same results
so how do i create an error message that will prevent the customer from going into the checkout until they have fixed up their cart
I would suggest you to make a dedicated page let's call it edit_cart. When you are redirecting to checkout, check all products and validate their qty in magento. Push them to edit_cart and let them delete out of stock products from cart. After this redirect them to checkout.

Drupal/Ubercart Check if a certain product is in the cart on checkout

I have one certain product that needs to be in the cart under certain circumstances. I have been looking at the Ubercart api documentation and I don't see any hooks that would be the obvious place to see if a certain item exists prior to checkout.
I could use the hook_add_to_cart hook to add the special item whenever the first item is added, but I'm concerned that the visitor may remove the item and then complete the purchase without the required item.
Any suggestions how to make sure the special item is in the cart on checkout?
You can have a module and run something like:
function mymodule_init() {
if (preg_match('/checkout/', request_uri()) {
$items = uc_cart_get_contents();
foreach ($items as $item) {
// code
}
}
}
That will fire up on the checkout page, and fetch the cart contents. Everytime they hit the checkout page, uc_cart_get_contents() returns the cart contents.
http://www.ubercart.org/docs/api/uc_cart_get_contents
There are probably better ways to do what you want to do though, like using a Conditional Action to prevent checkout if Item B is in the cart but Item A is not. You can also look at Product Kits, but I don't have much experience with that.
From what you have said it sounds as though the product kit module might be very much worth looking into as a way of ensuring any items associated with the main product are kept in the cart.
Product kit comes as part of ubercart and you will find it on the modules page under 'Ubercart - extra'. If this is no good then we can see about using the API :)
An old question, but I found a great solution.
hook_uc_cart_item_delete() functions specifically on certain entities when they are removed. You can just set this hook in your module, check for the specific entity being removed that is dependent on the other item, and then use uc_cart_remove_item() on the item you want to remove.

Where is the setCouponCode function is defined in Magento

I know that setCouponCode is catch inside __call in Varien_Object but I can't figure out where it is defined.
I need it because I want to show the coupon code even if the discount equal zero.
I believed it's done inside this function.
So if anybody know where the function is defined or where I can modify the code to get the coupon code displayed all the time, please let me know.
Most text editors have a 'search in files/folders' option. Open the source folder and search for function __setCouponCode.
Ok I figured it out.
the SetCouponCode is setting the value for coupon_code in the magic function.
Related to this, did anybody notice that the quote is not being deleted properly? I say it is related to this because the coupon code variable keeps the value [if any] after you delete a product from cart.
Try:
1. Set some Shopping Price Cart Rule to a product and make it display a banner on the header section for example.
2. Add product to checkout/cart in order to trigger the rule and show the banner on the Cart.
3. Delete the product from cart and you will see the banner still showing on the header section.
Note. If you have another product in cart this will not work because when you delete the one that triggered the rule&banner the Coupon Code will get replaced with the one that belongs to this other product in cart.
SO this bug only works if only the product that triggers the rule&banner is in cart.
If anybody has a fix on this or can replicate these conditions: I'd love to have a conversation about magento's deficiency to make a proper product delete from cart - which implies a proper quote refresh.
Reference:
- app/code/core/Mage/Sales/Model/Quote.php -> public function removeItem($itemId)
And yes, magento core issue.

Categories