Refresh of Shopping cart on item added - php

i am currently building a custom shopping cart to my website, it has all the items on the left and a slim view of the basket on the right with a list of all the items added plus a total value price. What i want is for the price and list to update when a user clicks on add to basket, but i don't want the page to reload, i know that AJAX can be used for this, but i was wondering if anyone had any tutorials that could show me some examples of being able to do this.
I am just getting a bit confused at the moment.
Thanks

there are many ajax shopping cart examples on internet, you can find them on google... for now here are some links for you
http://tutorialzine.com/2009/09/shopping-cart-php-jquery/
http://www.99points.info/2010/12/ajax-shopping-cart-with-jquery-and-php/

more than two hyperlinks are not allowed for me to post so i am posting hyperlinks without http :
net.tutsplus.com/tutorials/php/how-to-build-a-shopping-cart-using-codeigniter-and-jquery/
webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/

Related

WooCommerce Meta-key for products in cart

First post here so I'll try to make it as good as possible.
For a WooCommerce / WordPress project, I'm trying to achieve the following. When the cart is empty, there should be a button displayed with the text "Return to store".
Now the button isn't the problem, I've added this with Elementor, now usually I use the JetEngine Dynamic Visibility option to show/hide things.
I've also done this with stock status. There I used the _stock option to only display when there are 5 or more in stock left.
So I'm trying something similar with the cart, whenever there are 1 or more items in the cart, this button needs to be hidden because whenever someone has 1 item in their cart we want them to proceed to the checkout and not return to the shop, because the average product bought per order is 1 for this particular shop.
But the one thing I can figure out is, what key do I need to use to check items in the cart?
I've been trying several options I found online but none seem to work.
Does anyone know how to do this?
Thanks!

Woocommerce - Cart page - when cart gets renewed with new quantities, I want to be able to pass total

Ok - trying to slowly work my way through this - bear with me! Will try to describe what I'm doing here.
Using Woocommerce with theme called Flatsome - but this problem seems to relate to how Woocommerce updates the cart on the cart page.
So I am trying to bend Woocommerce to suit - so when client gets to Cart page - they do not move onto Checkout - instead I am giving them a Button to Request a Quotation - button when click opens a modal with a GravityForm in it.
I've been able to get the product list, quantities, price and SKU passed fine into the form ok using a 3rd party plugin ....
but boy oh boy - can I easily pass through the most recent TOTAL from woocommerce??
Not as easy as I'd hoped!
I had originally written this function into my functions.php
// Send the page url to parameter called 'gdcarttotal' for use in gravity forms
add_filter("gform_field_value_gdcarttotal", "populate_gd_carttotal");
function populate_gd_carttotal(){
global $woocommerce;
$totalamount = $woocommerce->cart->cart_contents_total;
return $totalamount;
}
And yes that seemed to pass through the Total of the Cart ok.
The problem arises if the quantities are updated whilst on that Cart page.
So if I update the quantity of a product - the totals etc all update fine on the Woocommerce cart page total BUT if I then click the launch Quotation form - the value for the Cart Total remains the value of the original total when user landed on that page. So it takes a full page refresh on the cart page to flush it and update it to the correct value.
Someone mentioned to me, Ajax which is beyond my capabilities.
Really just reaching out - and asking what is best way - or how could I write a function whilst on the cart page that will always give me the most updated TOTAL to pass through into a field on a form.
I've got a couple of screenshots but since my first time on here... I'm not sure if I can post or not. Hopefully this description tells the story.
Basically looking to know - whilst on the Woocommerce Cart page, how to pass the most recent TOTAL calculation to a form or page etc...
Thanks guys!!
Gareth
Your base issue is with the language you're using to solve the problem. You've written PHP, which is server-side (i.e., not real-time).
The WooCommerce cart is AJAX, a hybrid of JavaScript and XML, and it's processed client-side (i.e., in the browser) in real-time. That's how you are able to update the quantity and cart totals without a full page reload, and it's how the website is able to see how many items you have in the cart without reloading the page. Because of this, your solution needs to be client-side using JavaScript, I believe.
I'm not a pro developer, so I don't have the exact code to give you, but hopefully this gets you on the right track. You can also read more about AJAX here: https://www.w3schools.com/whatis/whatis_ajax.asp

Removing td.actions from cart page

I need to remove td.actions from a WooCommerce cart page via PHP. The table contains a Coupon field, and a Update Basket button. I searched around, but only found ways to hide using CSS. Any help is more than appreciated.

How Do I show the change of data on the same webpage using PHP?

I am building a food ordering website like FoodPanda as a project. Now among all pages , I have my order screen which will have two parts. On one side it will show the food items , clicking on which will add the items to my cart and on the other side I will show my cart. Now, what I want to do is I want to show the items added on my cart as soon as I press a button which will add them and show it in the same page without refreshing the webpage. How do I achieve this?
You'll be using JavaScript and Ajax for doing this. When some user click on a product to add it to the cart you'll need to send a post request with product details to a PHP script from where the item will be added to the cart and some result is returned. The returned result can be used for making decision of whether the item was added to the card successfully or not. If it is, you can add the item on the cart side using the JavaScript.

Is there a way to test a range of numbers on fiddler to add certain item to cart?

I don't know too much about programming but I was wondering if there was a way to 'bruteforce', I guess, the product IDs to find the one I am looking for on a website.
I am currently using Fiddler to add another item to cart and all that I need to figure out now is the product ID of the item that I actually want. This is the link to it.
If you are wondering why I am doing this, it is because I want to add the item to the cart so that as soon as it releases I can click checkout and buy the item. This shoe is limited and will have a lot of people with bots trying to buy it and I am just trying to do it with this way.

Categories