最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Remove item in Checkout

programmeradmin0浏览0评论

I am using this code for remove items in Checkout

add_filter('woocommerce_cart_item_name', 'custom_filter_wc_cart_item_remove_link', 10, 3);
function custom_filter_wc_cart_item_remove_link($product_name, $cart_item, $cart_item_key)
{
  
    if (is_checkout()) {

        $product_name .= apply_filters('woocommerce_cart_item_remove_link', sprintf(
            '<a href="%s" rel="nofollow" class="remove" style="float:left;">&times;</a>',
            esc_url(WC_Cart::get_remove_url($cart_item_key)),
            __('Remove this item', 'woocommerce'),
            esc_attr($cart_item['product_id']),
            esc_attr($cart_item['data']->get_sku())
        ), $cart_item_key);

        return $product_name;
    }
}

But it has an error because this line is old code

esc_url(WC_Cart::get_remove_url

Do you know how fix it

I am using this code for remove items in Checkout

add_filter('woocommerce_cart_item_name', 'custom_filter_wc_cart_item_remove_link', 10, 3);
function custom_filter_wc_cart_item_remove_link($product_name, $cart_item, $cart_item_key)
{
  
    if (is_checkout()) {

        $product_name .= apply_filters('woocommerce_cart_item_remove_link', sprintf(
            '<a href="%s" rel="nofollow" class="remove" style="float:left;">&times;</a>',
            esc_url(WC_Cart::get_remove_url($cart_item_key)),
            __('Remove this item', 'woocommerce'),
            esc_attr($cart_item['product_id']),
            esc_attr($cart_item['data']->get_sku())
        ), $cart_item_key);

        return $product_name;
    }
}

But it has an error because this line is old code

esc_url(WC_Cart::get_remove_url

Do you know how fix it

Share Improve this question edited Nov 29, 2020 at 14:34 Rup 4,4004 gold badges29 silver badges29 bronze badges asked Nov 29, 2020 at 12:39 LaurapnunezLaurapnunez 11 bronze badge 2
  • In the future if you have an error message could you please include it in your question? Thanks! – Rup Commented Nov 29, 2020 at 14:35
  • But if it was a deprecated function error I'd be surprised if the error didn't tell you which function to use instead. – Rup Commented Nov 29, 2020 at 14:36
Add a comment  | 

1 Answer 1

Reset to default 1

that function is deprecated, use wc_get_cart_remove_url( $cart_item_key ) instead

if (is_checkout()) {
    $product_name .= apply_filters('woocommerce_cart_item_remove_link', sprintf(
        '<a href="%s" rel="nofollow" class="remove" style="float:left;">&times;</a>',
        esc_url(wc_get_cart_remove_url($cart_item_key)),
        __('Remove this item', 'woocommerce'),
        esc_attr($cart_item['product_id']),
        esc_attr($cart_item['data']->get_sku())
    ), $cart_item_key);

    return $product_name;
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论