简体   繁体   English

WooCommerce 将多个产品的自定义重定向添加到购物车

[英]WooCommerce Add to Cart custom redirection for multiple products Variations

i use woocomerce Add to Cart custom redirection for multiple products this is my working code:我对多个产品使用 woocomerce 添加到购物车自定义重定向这是我的工作代码:

add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect', 10, 2 );
function custom_add_to_cart_redirect( $redirect_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( 3008 ) ) ) {
     wp_redirect( 'www...' );
             exit;
    }
    if ( in_array( $product_id, array( 2992 ) ) ) {
     wp_redirect( 'www...' );
             exit;
    }
    return $redirect_url;
}

i need edit this code for variations product i try this but didn't work :我需要为变体产品编辑此代码我尝试了这个但没有奏效:

add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect', 10, 2 );
function custom_add_to_cart_redirect( $redirect_url ) {
    $variation_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( $variation_id, array( 3008 ) ) ) {
     wp_redirect( 'www...' );
             exit;
    }
    if ( in_array( $variation_id, array( 2992 ) ) ) {
     wp_redirect( 'www...' );
             exit;
    }
    return $redirect_url;
}

You need to swap out this line你需要换掉这条线

$variation_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) );

With this有了这个

$variation_id = absint( $_REQUEST['variation_id'] );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WooCommerce:更改多个产品的添加到购物车按钮文本,并重定向到结帐 - WooCommerce: Change add to cart button text for multiple products with a redirection to checkout WooCommerce 添加<custom>产品到购物车</custom> - WooCommerce Add <custom> products to cart 在访问WooCommerce时自动将多种产品添加到购物车 - Automatically add multiple products to cart on visit WooCommerce 在 WooCommerce 中添加并显示多个自定义字段 - Add and display multiple Custom Fields for Variations in WooCommerce 单个 Woocommerce 产品自定义变体添加到购物车按钮 - Single Woocommerce product custom variations add to cart buttons 在WooCommerce中添加两个不同的产品和自定义添加到购物车() - Add two different Products with Custom Add-To-Cart() in WooCommerce 如何在 WooCommerce 中的自定义添加到购物车按钮上重定向到结帐 - How to make a redirection to checkout on a custom add to cart button in WooCommerce WooCommerce 3中定义的产品类别的自定义添加到购物车重定向 - custom add to cart redirection for a defined product category in WooCommerce 3 WooCommerce 添加到购物车针对特定产品 ID 的自定义重定向 - WooCommerce Add to Cart custom redirection for specific product IDs 基于付款后购买的多个产品的 Woocommerce 自定义重定向 - Woocommerce custom redirection based on purchased multiple products after payment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM