This question already has answers here:
Only one currently added product into Woocommerce cart?
(2 answers)
WooCommerce - Skip cart page redirecting to checkout page
(1 answer)
Closed 4 years ago.
I am trying to remove the full cart feature from WooCommerce. I want when some one click on the buy now button they should go directly to the checkout page.
** I have tried few plugins but those don't remove the full cart feature. They just redirect to the checkout page.
** So with the plugins my problem was if someone leave from the checkout page and try to buy the same product or an another product the previous product was in the cart. and in the checkout page there was 2 products.
Can someone tell me how can i remove the full cart feature from the woo-commerce? Is it possible?
So if you want to always have only one item in your cart you add this to your functions.php
add_filter( 'woocommerce_add_to_cart_validation', 'remove_cart_item_before_add_to_cart', 20, 3 );
function remove_cart_item_before_add_to_cart( $passed, $product_id, $quantity ) {
if( ! WC()->cart->is_empty())
WC()->cart->empty_cart();
return $passed;
}
It will empty your cart before adding the new item to it. And you can keep your plugin that is redirecting you to checkout or code it in php probably with something like that :
add_action( 'template_redirect', 'redirect_cart_to_checkout' );
function redirect_cart_to_checkout() {
if( is_cart()){
wp_redirect(wc_get_checkout_url());
die;
}
}
Related
This question already has answers here:
Add extra details Woocommerce order edit pages in admin
(2 answers)
Closed 11 months ago.
I am saving some extra products to order meta during checkout and I want to show those products into woocommerce admin order details section and it need to look like regular products.
I am looking for any woocommerce hooks available to acheive this task without customization woocommerce core file.
I'm not sure I totally understand but is this what you mean?:
add_action( 'woocommerce_after_order_itemmeta', 'custom_info_after_order_itemmeta', 20, 3 );
function custom_info_after_order_itemmeta( $item_id, $item, $product ) {
//echo stuff here
}
This question already has answers here:
How can I remove Shipping from a WooCommerce cart? [closed]
(2 answers)
Shipping methods only enabled in checkout page on Woocommerce
(1 answer)
Closed 2 years ago.
Want to Remove Woocommerce Shipping in checkout Page
I have attacked an Image Please check it
https://prnt.sc/waue9w
You can use the following code to remove shipping in checkout page:
function disable_shipping_calc_on_cart( $show_shipping ) {
if (is_checkout()){
return false;
}
return $show_shipping;
}
add_filter( 'woocommerce_cart_ready_to_calc_shipping', 'disable_shipping_calc_on_cart', 99 );
I’ve added the following filter (see below) for the scenario that a customer adds another (individually sold, digital) product to the cart that is already in the cart.
It was a nice way to disable the kind of ugly “you cannot add another product” message in a case that happened and just show the cart (as a reminder that the product is already in the cart)
With the new 3.7 woocommerce update, the appearing circle on top of the ajax "buy button" is stuck in an endlessly spinning loop.
In the version before the circle started spinning, it stopped, the cart appeared to show the customer that the product is already in the cart.
Did woocommerce change the variables that are involved in the filter below or is there another easy fix that I'm not aware of?
// if product is already in cart, just go to cart and don’t show ugly “you cannot add another product” message
add_filter( ‘woocommerce_add_to_cart_sold_individually_found_in_cart’, ‘spark_redirect_to_cart’ );
function spark_redirect_to_cart( $found_in_cart ) {
if ( $found_in_cart ) {
wp_safe_redirect( wc_get_page_permalink( ‘cart’ ) );
exit;
}
return $found_in_cart;
}
Help is very much appreciated, thanks.
Or is this bug related to the flatsome theme I'm using.
This question already has answers here:
Remove rel="nofollow" from woocommerce 'add to cart' buttons
(2 answers)
Closed last year.
I have found a few versions of code that can be added to remove the nofollow from the 'add to cart' links in woocommerce.
The most recent code I found is:
add_filter( 'woocommerce_loop_add_to_cart_args', 'remove_rel', 10, 2 );
function remove_rel( $args, $product ) {
unset( $args['attributes']['rel'] );
return $args;
}
Will this do the job and where do I put the code? I believe it needs to be put in the functions.php file but sometimes it mentions it needing to be in a child theme and others don't mention a child theme at all.
Any help would be great.
Thanks
This code works with WooCommerce 3.5.3. Add it to the functions.php of whichever theme you are using.
I am trying to programmatically add a booking to the shopping cart. I have been looking into the code for this and have found and tried the following:
Method 1: $woocommerce->cart->add_to_cart( $product_id);
Method 2: WC()->cart->add_to_cart( $product_id );
Neither of which are working for me with the latest release of woocommerce bookings.
The code works for simple products in woocommerce without issue. Any help would be greatly appreciated