Home / eCommerce / WWPP & Elementor – Show correct wholesale prices in the Elementor side cart
Duplicate Snippet

Embed Snippet on Your Site

WWPP & Elementor – Show correct wholesale prices in the Elementor side cart

Code Preview
php
<?php
/**
 * WWPP & Elementor: show correct wholesale prices in Elementor side cart.
 */
add_filter( 'woocommerce_cart_item_price', function ( $price_html, $cart_item, $cart_item_key ) {
    if ( is_cart() || is_checkout() ) {
        return $price_html;
    }
    global $wc_wholesale_prices_premium, $wc_wholesale_prices;
    if ( ! isset( $wc_wholesale_prices_premium ) ) {
        return $price_html;
    }
    $user_wholesale_role = $wc_wholesale_prices_premium->wwpp_wholesale_roles->getUserWholesaleRole();
    if ( empty( $user_wholesale_role ) ) {
        return $price_html;
    }
    $product_id      = ! empty( $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id'];
    $wholesale_data  = WWP_Wholesale_Prices::get_product_wholesale_price_on_shop_v3( $product_id, array( $user_wholesale_role ) );
    $wholesale_price = isset( $wholesale_data['wholesale_price'] ) ? (float) $wholesale_data['wholesale_price'] : 0;
    if ( $wholesale_price <= 0 ) {
        return $price_html;
    }
    if ( isset( $wc_wholesale_prices->wwp_wholesale_prices ) ) {
        remove_filter(
            'woocommerce_cart_item_price',
            array( $wc_wholesale_prices->wwp_wholesale_prices, 'filter_product_price' ),
            100
        );
    }
    $product = wc_get_product( $product_id );
    return wc_price( wc_get_price_to_display( $product, array( 'price' => $wholesale_price ) ) );
}, 25, 3 );

Comments

Add a Comment