[英]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.