How I can delete checkout step in my woocommerce store? - php

I created a store by woocommerce and I want redirect customer to payment gateway or reduce wallet after click " add to cart". in other way I want to bypass checkout step.

First, in the admin, go to WooCommerce > Settings > Products and disable both options under Add to Cart Behavior. The two options that you need to disable are:
Redirect to the cart page after successful addition
Enable AJAX add to cart buttons on archives
Next, in your theme's functions.php file, add the following code:
function so55387651_redirect_checkout_add_cart( $url ) {
$url = get_permalink( get_option( 'woocommerce_checkout_page_id' ) );
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'so55387651_redirect_checkout_add_cart' );

Related

Move cart.php and cart-totals.php to checkout page

To reduce the number of redirects on my site, i added the cart page on the same page as the checkout. and used this code to do it:
function cart_on_checkout_page_only() {
if ( is_wc_endpoint_url( 'order-received' ) ) return;
// add woocomerce cart shortcode on checkout page
echo do_shortcode('[woocommerce_cart]');
}
// Cart and Checkout same page
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page_only', 5 );
The problem is in the layout specifically, on devices it is too far from the order items as the order total is at the bottom of the page near the checkout button. I got a lot of complaints because people are too lazy to scroll down to see the coupon application in the cart at the bottom of the page
so I made the following modification:
I copied the woocommerce plugin files woocommerce/template/cart/cat.php and cart-totals.php
and pasted it into my theme in themes/mytheme/template/cart/custom-cart.php
and adapted it in the code above:
function cart_on_checkout_page_only() {
if ( is_wc_endpoint_url( 'order-received' ) ) return;
// add custom cart template on checkout page
get_template_part('template/cart/custom-cart');
}
// Cart and Checkout same page
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page_only', 5 );
my code did the job, but I believe there should be a simpler and more elegant way to make this kind of change. it's possible to make more simpler?
by the way I'm using a child storefront theme.

How to remove woocommerce added cart items and redirect to checkout?

I have a Woocommerce form to 'Add Funds'. It has an amount input field ($20, $30 ...etc.) and a submit button that redirects to cart page with the input amount as total.
Redirect to checkout is working, but the cart items are not getting removed if a user abandons the cart and tries to order again.
I tried numerous solutions for the redirect to checkout, but only one worked.
Working solution for redirect to checkout:
WooCommerce - Skip cart page redirecting to checkout page
Solutions not working for redirect to checkout:
https://wordpress.stackexchange.com/questions/267071/redirect-to-woocommerce-checkout-after-adding-to-cart-item-already-in-cart
Woocommerce add to cart button redirect to checkout
N.B. I have added the working and not working solutions for redirect
to checkout because it may provide an insight as to why the empty cart
solutions are not working.
Incase of emptying cart before adding a new product, none of the solutions are working:
https://gist.github.com/viniciusrtf/b49403b5f87dcd7699c1
https://hungred.com/how-to/empty-woocommerce-cart-adding-item/
https://wordpress.stackexchange.com/questions/267071/redirect-to-woocommerce-checkout-after-adding-to-cart-item-already-in-cart
Using Woocommerce 3.2.6 and WordPress 4.9.2
First you will need in WooCommerce Settings > Products > Display in "Add to cart behaviour" to enabled the checkbox : Redirect to the cart page after successful addition
Then you will need the 3 following hooked function:
1) Empty cart before add-to-cart (if cart is not empty)
add_filter( 'woocommerce_add_to_cart_validation', 'one_cart_item_at_the_time', 10, 3 );
function one_cart_item_at_the_time( $passed, $product_id, $quantity ) {
if( ! WC()->cart->is_empty())
WC()->cart->empty_cart();
return $passed;
}
2) Add-to-cart redirection to checkout:
add_filter( 'woocommerce_add_to_cart_redirect', 'add_to_cart_checkout_redirection', 10, 1 );
function add_to_cart_checkout_redirection( $url ) {
return wc_get_checkout_url();
}
3) Skip cart page redirecting to checkout:
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
function skip_cart_page_redirection_to_checkout() {
if( is_cart() )
wp_redirect( wc_get_checkout_url() );
}
Code goes in function.php file of your active child theme (or active theme).
Tested and works (with Woocommerce 3.2.6 and WordPress 4.9.2 on Storefront theme).

Disable ajax for add to cart button in single product page / Wordpress / Woocommerce

I am developing an eCommerce website using wordpress, cartify theme, woocommerce 3.0.3.
I would like to redirect after to cart or checkout after clicking the buy now product.
Here you can see the page
**Add to cart behaviour**
✔︎ Redirect to the cart page after successful addition
(Unchecked) Enable AJAX add to cart buttons on archives
I activated redirect to cart after add to cart click and left in the woo commerce options but it seems to still using ajax.
**WooCommerce System status**
MySQL version: 5.5.51 - We recommend a minimum MySQL version of 5.6.
(THE HOST PROVIDER DOESN'T ALLOW ME TO UPGRADE)
WC pages
My account: Page does not contain the shortcode.
cartify/woocommerce/single-product/product-image.php version 2.6.3 is out of date. The core version is 3.0.2,
cartify/woocommerce/single-product/product-thumbnails.php version 2.6.3 is out of date. The core version is 3.0.2,
This two really mess my site when I update them.
Any suggestions, please?
Thank you in advance for your help
SO here I am going to explain three steps
Step 1 if you want customer to redirect after adding to cart to checkout then add below code to the functions.php
function my_custom_add_to_cart_redirect( $url ) {
$url = WC()->cart->get_checkout_url();
// $url = wc_get_checkout_url(); // since WC 2.5.0
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
Step 2 if you want customer to redirect to the cart page after add to cart the following image link showing you can do this from admin end
http://prntscr.com/ewo99j
Step 3 if from admin end it's not redirecting the customer to the cart page then add following code to your functions.PHP
function custom_add_to_cart_redirect() {
return 'http://localhost:8080/wordpress2/cart/';
}
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );
replace this URL http://localhost:8080/wordpress2/cart/ with your cart page URL
hope it will work for you
Thanks
You can use this jquery in your theme.
$(document).ready(function() {
$(".add_to_cart_button").removeClass("ajax_add_to_cart")
});
Then you can use this code in your functions.php for redirect into the checkout page:
add_filter('woocommerce_add_to_cart_redirect','themeprefix_add_to_cart_redirect');
function themeprefix_add_to_cart_redirect() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
}

Disabling cart page

I would like to disable the WooCommerce cart functionality by all means.
My shop has only a single product, so cart is doesn't really needed.
My desired flow is Click on buy button -> go to checkout page.
Incase user goes back and redo the same process, checkout page will not show 2 products in summary buy just 1.
Any tips on how to achieve this smoothly ?
Thanks,
You will Need 4 code snippets:
1) Disabling quantities buttons (on product page):
add_filter( 'woocommerce_is_sold_individually', '__return_true' );
2) Add-to-cart validation, allowing just one product in cart:
add_action( 'woocommerce_add_to_cart_validation', 'check_product_is_in_cart' );
function check_product_is_in_cart() {
WC()->cart->empty_cart();
return true;
}
3) Checkout redirect customer when your product is added to cart (with modern syntax):
add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
return WC()->cart->get_checkout_url();
// OR ALSO:
// return get_permalink(get_option('woocommerce_checkout_page_id'));
}
The code comme from this answer (with the correct new syntax): Woocommerce add to cart button redirect to checkout
4) Redirect Cart page to Checkout page (in case of):
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
function skip_cart_page_redirection_to_checkout() {
if(is_cart()){
wp_redirect(WC()->cart->get_checkout_url());
// OR ALSO:
// wp_redirect( get_permalink( get_option( 'woocommerce_checkout_page_id' ) ) );
exit; // This is mandatory with wp_redirect()
}
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Code is tested and works.
Disabling redirect to Cart on add-to-cart action and Ajax add-to-cart on Shop page and archives pages (optional)
You can also disable some settings in WooCommerce > Settings > Products > Display (tab).
Optionally keep that 2 options disabled (and save settings):
If you need to skip the cart page the easiest way it is to go to the Woocommerce->Settings->Checkout and set Cart Page to "Checkout" page
Or use this snippet
add_filter('add_to_cart_redirect', 'themeprefix_add_to_cart_redirect');
function themeprefix_add_to_cart_redirect() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
}
Don't forget to disable Ajax Add to cart and Redirect to the cart page after successful addition in Woocommerce->Settings->Products->Display
If you use the first method you can check the Redirect to the cart page after successful addition.
For the limit one item in checkout use this snippet.
In this way, the customer only can buy one item, if the customer goes to another product and tries to buy it, the cart will be cleaned and the last item added.
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();
return $cart_item_data;
}

WooCommerce - Skip cart page redirecting to checkout page

Our website is kohsamuitour.net. I have added custom code to skip the cart page on checkout, which works for all sales. This code:
function wc_empty_cart_redirect_url() {
return 'https://www.kohsamuitour.net/all-tours/';
}
add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );
Now that does the job, but we also have a possibility to check booking availability. That can be found on the pages of private charters, i.e. this one: https://www.kohsamuitour.net/tours/kia-ora-catamaran/ .
Here the customer is being redirected to the cart, where I don't want that to happen as this is not a sale.
How can I make sure the 'Check booking availability' is also redirected to the checkout straight away?
You can skip cart definitively, redirecting customers to checkout page when cart url is called.
To achieve this use this code snippet, that should do the trick:
// Function that skip cart redirecting to checkout
function skip_cart_page_redirection_to_checkout() {
// If is cart page, redirect checkout.
if( is_cart() )
wp_redirect( WC()->cart->get_checkout_url() );
}
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
Edit: Since WooCommerce 3 replace wp_redirect( WC()->cart->get_checkout_url() ); by:
wp_redirect( wc_get_checkout_url() );

Categories