Add fields to woocommerce cart page - wordpress

I want to add one or two fields on cart page. I want to take my users preferred delivery time.
for example I am selling cakes and want users preferred date and time when they want it.
I want it on carts page not on checkout page.
Thank you

I figured out the way.
add_action( 'woocommerce_after_cart_table', 'custom_timing_fields' );
function custom_timing_fields() {
echo "something like input or select box here";
}

Related

how to prevent same product adding multiple times to cart when I want my visitor to directly go to checkout

Let say someone decides to buy my product and click on the buy now option and reached my checkout page. But for some reason he/she didn't buy it.
But after sometime he/she made his mind to purchase the product but when they click on buy know button the product price get doubles because the product is added a second time in the cart.
As i am not giving access to the cart page to my visitor so they can't modify there cart.
Is there anyway with which I can prevent the same product adding a second time in cart.
I don't want the min maximum plugin because it doesn't prevent from adding same product multiple time. It just shows a notification that the max amount is 1.
I just don't want the same product to be addded twice in the cart no matter what.
I tried this code:
add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' );
function woo_custom_add_to_cart( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return $cart_item_data;
}
But after adding it I am not able to add a second product into my cart.
As I have added a order bump in my checkout page but when i tried to add it it replaced the main product.
You can force a single purchase of a given product from Edit Product > Product Data > Inventory > Sold Individually
No code needed

Woocommerce hides cart_totals when using cart and checkout on same page

On my cart page I updated it to include the two short codes:
[woocommerce_cart] – shows the cart page
[woocommerce_checkout] – shows the checkout page
By default the cart page is only populated with [woocommerce_cart] and it will show the cart, coupon code area, and cart totals. When I add the [woocommerce_checkout] it removes the cart totals box.
Does anyone know a work around for this? Or know of this problem?
WooCommerce hides the cart totals by default when the checkout is also present on the same page. This is because it gives duplicate information that might be confusing for your customer, since the checkout also displays subtotal, total and shipping information.
You could bring the cart totals back with a snippet like this:
add_action( 'woocommerce_after_cart_table', 'woocommerce_show_cart_totals', 10 );
function woocommerce_show_cart_totals() {
wc_get_template( 'cart/cart-totals.php' );
}
But changing the shipping method for instance wouldn't work as the shipping method option of the checkout would overwrite again what you have selected in the cart totals.

Creating extra Buy now button on woocommerce product

I want to create a new buy now sort of button besides the real buy now button on a woocommerce product. The function for this will be to be able to trade a product with another product, so when clicking this new buy now, it will open a custom popup, with image fields and the ability to add extra cash on top of the product - the seller will then be able to accept or deny the offer - how do i go about it? We use Woocommerce, Buddypress, And WooCommerce vendors - how can we do this?
After accepting it will go to checkout for buyer.
Thanks.
This code will create extra button on single product page beside add to cart button.
add_action('woocommerce_after_add_to_cart_button','additional_button');
function additional_button(){
echo '<input type="button" name="trade_product" value="Trade Product />"';
}

WooCommerce - Remove cart?

I want to take a straight payment for the one item, not have multiple items and cart functionality.
This is what I have so far:
User views product, presses buy and goes to checkout (via a straight checkout link), problem is here is that at the top of the checkout page it says “XXXX product has been added to cart – View Cart”. I don’t want this cart part there it should just go straight to the checkout and take the payment.
Another problem is if they go back through my funnel it adds a second item into the cart. I only want them to be able to purchase a quantity of 1 so I don't need any cart functionality just a straight checkout.
How can this be done?
Thanks
Try the following code redirect users to Checkout Page after add to cart.
/**
* Redirect users to Checkout Page after add to cart.
*/
function my_custom_add_to_cart_redirect( $url ) {
$url = WC()->cart->get_checkout_url();
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
You can also try this plugin https://wordpress.org/plugins/woocommerce-direct-checkout/

woocommerce add_to_cart

When I program:
$woocommerce->cart->add_to_cart( $group_product_id, 1);
with $group_product_id being the product post ID (e.g. 300), the shopping cart shows a quantity of 2 not 1.
When I directly enter the URL (e.g.http://www.mystore.com/shop/stuff?add_to_cart=300), the shopping cart shows a quantity of 1 (the correct expected behavior).
Any suggestions would be really helpful.
Thank you.
P.S. Bonus question: is there any way to program adding multiple items to the cart (not grouped or variations) before taking the user to the cart page?
Grouped products cannot be added to cart directly. Group product is actually a group of simple products. So $group_product_id should be the id of any of the simple products which constitute the grouped product.
The first two parameters you must use on $woocommerce->cart->add_to_cart, are, $product->id and/or quantity to add. The post id has nothing to do here.
You can yes add multiple products at once using ajax calls, but is not so simple to describe on a comment, will depend on your configuration, your theme, etc, but yes, it´s posible, in fact i recently did something like that. The point is to use syncronized ajax calls that actualy call the add_to_cart function. You can use jquery for triggering many add to cart buttons at same time.

Resources