这是我的解决方案(如果用户单击自定义的“添加到购物车”按钮,则重定向到签出页面):
function xnagyg_redirect_checkout_add_cart( $url ) {
//continue only if we found add-to-cart in the URL!!!
if ( empty( $_GET[\'add-to-cart\'] ) || ! is_numeric( $_GET[\'add-to-cart\'] ) ) {
return false; //do not redirect
}
$url = get_permalink( get_option( \'woocommerce_checkout_page_id\' ) ); //Redirect to Checkout page
return $url;
}
add_filter( \'woocommerce_add_to_cart_redirect\', \'xnagyg_redirect_checkout_add_cart\' );