Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Last active November 25, 2018 13:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikejolley/1622409 to your computer and use it in GitHub Desktop.
Save mikejolley/1622409 to your computer and use it in GitHub Desktop.
WooCommerce - Set a custom add to cart URL to redirect to
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );
function custom_add_to_cart_redirect() {
/**
* Replace with the url of your choosing
* e.g. return 'http://www.yourshop.com/'
*/
return get_permalink( get_option('woocommerce_checkout_page_id') );
}
@BFTrick
Copy link

BFTrick commented Jan 3, 2015

We should change the filter from add_to_cart_redirect to woocommerce_add_to_cart_redirect

@Yahyaconsultants
Copy link

Thank you for sharing this.

if I wanted to add a product ID at the end of the URL how would I do that this is what I have done

function custom_add_to_cart_redirect() {

global $post,$product;
$id = $product->id;

$URL= "https://yahyaprints.com/product/$id";

 return $URL 
    
    ;

}

add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );

but it does not work ? can you please help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment