WooCommerce购物车项目编号基于独特的产品

时间:2019-08-02 08:28:12

标签: wordpress woocommerce

有什么方法可以仅基于独特商品来更改购物车编号中的商品吗? 我找不到开始玩的东西。任何帮助,不胜感激! 例: 笔3x 书2x

当前: 购物车上有5件物品

应该是:

购物车上有2件商品。

谢谢

这是主题的当前代码,我针对kleo通知新警报:

    if ( ! function_exists( 'kleo_woo_get_mini_cart' ) ) {
    function kleo_woo_get_mini_cart( $just_inner = false ) {

    global $woocommerce;


    //Enqueue variations script for quick view
    wp_enqueue_script( 'wc-add-to-cart-variation' );

    $cart_output     = "";
    $cart_total      = $woocommerce->cart->get_cart_total();
    $cart_count      = $woocommerce->cart->cart_contents_count;
    $cart_count_text = kleo_product_items_text( $cart_count );

    $cart_has_items = '';
    if ( $cart_count != "0" ) {
        $cart_has_items = ' has-products';
    }

    if ( ! $just_inner ) {
        $cart_output .= '<li class="menu-item kleo-toggle-menu shop-drop">'
                        . '<a class="cart-contents js-activated" href="' . wc_get_cart_url() . '" title="' . __( "View Cart", "woocommerce" ) . '">'
                        . '<span class="cart-items' . $cart_has_items . '"><i class="icon icon-basket-full-alt"></i> ';

        if ( $cart_count != "0" ) {
            $cart_output .= "<span class='kleo-notifications new-alert'>" . $cart_count . "</span>";
        }

1 个答案:

答案 0 :(得分:0)

add_filter( 'woocommerce_add_to_cart_fragments', 'test_cart_count_fragments', 20, 10 );
function test_cart_count_fragments( $fragments ) { 
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
    $fragments['span.new-alert'] = '<span class="kleo-notifications new-alert">' . count($items). '</span>';

    return $fragments;

}