Created
August 3, 2016 18:36
-
-
Save jamc92/6478ef30b984c8e72233750565bedce0 to your computer and use it in GitHub Desktop.
WooCommerce conditionally redirect users after add to cart - Shipping class
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
<?php | |
/** | |
* Redirect users after add to cart. | |
*/ | |
function my_custom_add_to_cart_redirect( $url ) { | |
if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( $_REQUEST['add-to-cart'] ) ) { | |
return $url; | |
} | |
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) ); | |
// Only redirect products with the 'small-item' shipping class | |
if ( has_term( 'small-item', 'product_shipping_class', $product_id ) ) { | |
$url = WC()->cart->get_checkout_url(); | |
} | |
return $url; | |
} | |
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' ); | |
view raw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment