我正在尝试将所有产品重定向到一个自定义页面,除了 3 个进入结帐的产品(这部分有效)。
function my_custom_add_to_cart_redirect( $url ) {
if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( $_REQUEST['add-to-cart'] ) ) {
$url = get_permalink( 16 ); // URL page ID to redirect for all pages but below mentioned
return $url;
}
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) );
// Only redirect the product IDs in the array to the checkout
if ( in_array( $product_id, array( 999, 997, 872) ) ) {
$url = WC()->cart->get_checkout_url();
}
return $url;
}
add_filter( …
Run Code Online (Sandbox Code Playgroud)