简体   繁体   English

如何将购物车商品产品重定向到Woocommerce中的特定页面?

[英]How can i redirect cart item product to specific page in Woocommerce?

I want to like once click on cart item product it'll be redirect to custom page. 我想要一次点击购物车商品,它将被重定向到自定义页面。 Following image is cart page 以下图片是购物车页面 在此输入图像描述

I have tried following script but not work. 我试过以下脚本但没有工作。

   add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_on_add_to_cart' );
function redirect_on_add_to_cart() {
        if ( isset( $_POST['add-to-cart'] ) ) {
            $product_id = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $_POST['add-to-cart'] );

            if($product_id == 322 || $product_id == 320){
                return get_permalink( 30 );
            }       
        }
}

I did this using woocommerce_cart_item_permalink filter hook 我使用woocommerce_cart_item_permalink过滤器钩子做了这个

function filter_woocommerce_cart_item_permalink($product_get_permalink_cart_item, $cart_item, $cart_item_key){
  $productId = $cart_item['product_id'];
  $customUrl = get_permalink( get_page_by_path( 'box_select_product' ) );
  $updatLink =add_query_arg( 'product_box_id', $productId, $customUrl );
  return $updatLink; 
}

add_filter( 'woocommerce_cart_item_permalink', 'filter_woocommerce_cart_item_permalink', 10, 3 ); 

暂无
暂无

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

相关问题 如何在 Woocommerce 中将特定类别的产品页面重定向到购物车页面 - How to Redirect specific category product pages to cart page in Woocommerce 在 WooCommerce 购物车页面的购物车商品名称后添加产品 ID 用于特定产品 - Add the product ID after the cart item name in WooCommerce cart page for specific products 如何在图像中添加产品永久链接标记woocommerce购物车项目? - How can add product permalink in image a tag woocommerce cart item? 在 Woocommerce 购物车页面上显示特定的产品属性 - Display specific product attribute on Woocommerce cart page 基于 Woocommerce 中特定产品类别购物车项目数量的购物车费用 - Cart fee based on specific product category cart item quantity in Woocommerce WooCommerce:如果特定产品是购物车中的唯一商品,请清除购物车 - WooCommerce: If specific product is the only item in cart, clear cart 如果还添加了特定产品,如何从 WooCommerce 的购物车中删除其他产品? - How can I remove other products from my cart in WooCommerce if a specific product is also added? 在 Woocommerce 购物车页面中的购物车项目名称后添加产品 ID - Add the product ID after the cart item name in Woocommerce cart page 如何在空购物车页面中保存访客在woocommerce中添加到购物车的第一个商品的产品ID? - How save product id of 1st item added to cart in woocommerce for a visitor in empty cart page? 如果我单击已在购物车中的产品的“添加到购物车”按钮,如何重定向到购物车页面 - How do I redirect to the cart page if I click on the 'Add to cart' button for a product that's already in cart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM