禁用Woocommerce购物车结帐和订单中特定产品的商品名称链接

问题描述 投票:3回答:1

我打算禁用产品链接到购物车中特定产品的产品页面。当购物车小计金额等于特定值时,此产品是自动添加到购物车的礼品。

我知道可以对所有购物车项目进行此操作。但我不太确定如何定位特定项目。

php wordpress woocommerce cart checkout
1个回答
1
投票

更新:添加了一个钩子函数来处理minicart

要从购物车,结帐和订单中删除商品名称链接,请使用以下内容:

// Cart item link
add_filter( 'woocommerce_cart_item_name', 'conditionally_remove_link_from_cart_item_name', 10, 3 );
function conditionally_remove_link_from_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
    // HERE set your Free product ID
    $gift_product_id = 37;

    if( $gift_product_id == $cart_item['data']->get_id() ) {
        $item_name = $cart_item['data']->get_name();
    }
    return $item_name;
}

// Mini-cart item link
add_filter( 'woocommerce_cart_item_permalink', 'conditionally_remove_cart_item_permalink', 10, 3 );
function conditionally_remove_cart_item_permalink( $permalink, $cart_item, $cart_item_key ) {
    // HERE set your Free product ID
    $gift_product_id = 37;

    if( $gift_product_id == $cart_item['data']->get_id() ) {
        $permalink = '';
    }
    return $permalink;
}

// Order item link
add_filter( 'woocommerce_order_item_name', 'conditionally_remove_link_from_order_item_name', 10, 2 );
function custom_order_item_name( $item_name, $item ) {
    // HERE set your Free product ID
    $gift_product_id = 37;

    if( $gift_product_id == $item->get_product_id() ) {
        $item_name = $item->get_name();
    }
    return $item_name;
}

代码位于活动子主题(或活动主题)的function.php文件中。经过测试和工作。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.