简体   繁体   中英

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

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 ); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM