Forked from JeroenSormani/wc-redirect-after-add-to-cart.php
Created
August 17, 2018 08:46
-
-
Save seredniy/093f0f8637632264c1e1a9e91fa466fd to your computer and use it in GitHub Desktop.
WooCommerce redirect after add to cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Redirect to checkout at add-to-cart action. | |
*/ | |
function redirect_to_checkout() { | |
return WC()->cart->get_checkout_url(); | |
} | |
add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_to_checkout' ); | |
------------------------------------ | |
/** | |
* Redirect to checkout at add-to-cart action on specific product IDs. | |
* When not in the list of IDs it will go to the cart (default behaviour). | |
*/ | |
function redirect_to_checkout_product_ids( $url ) { | |
if ( in_array( $_REQUEST['add-to-cart'], array( 1, 2, 3 ) ) ) : | |
$url = WC()->cart->get_checkout_url(); | |
endif; | |
return $url; | |
} | |
add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_to_checkout_product_ids' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment