Created
July 16, 2015 14:49
-
-
Save irkanu/01c3cadc2db9b5f9be5a to your computer and use it in GitHub Desktop.
Trying to redirect to checkout only if the product has a "Trial" category.
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
add_filter( 'woocommerce_add_to_cart_redirect', 'example_redirect_to_checkout' ); | |
function example_redirect_to_checkout() { | |
$redirect_url = WC()->cart->get_checkout_url(); | |
if ( is_product() && has_term( 'Trial', 'product_cat' ) ) { | |
return $redirect_url; | |
} | |
} |
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
add_action( 'wp', 'example_add_redirect' ); | |
function example_add_redirect() { | |
if ( is_product() && has_term( 'Trial', 'product_cat' ) ) { | |
add_filter( 'woocommerce_add_to_cart_redirect', 'example_redirect_to_checkout' ); | |
} | |
} | |
function example_redirect_to_checkout() { | |
$redirect_url = WC()->cart->get_checkout_url(); | |
return $redirect_url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment