Skip to content

Instantly share code, notes, and snippets.

@rayflores
Created June 6, 2014 05:32
Show Gist options
  • Save rayflores/c1d03823e4f4f8860f9e to your computer and use it in GitHub Desktop.
Save rayflores/c1d03823e4f4f8860f9e to your computer and use it in GitHub Desktop.
<?php
/**
* Redirect directly to checkout page only for ONE product
* if cart contains $product_id then go directly to checkout.
**/
add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
global $woocommerce;
//Get product ID
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) );
//Check if product ID is in a certain taxonomy
if( $product_id = 6319){
//Get cart URL
$checkout_url = get_permalink(get_option('woocommerce_checkout_page_id'));
//Return the new URL
return $checkout_url;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment