Improved compatibility for WooCommerce Wholesale Prices by Rymera Web Co

Enhance compatibility with WooCommerce Wholesale Prices plugin by Rymera Web Co.

// Note: Disable inbuilt compactibility of WooCommerce Wholesale Prices in order to work
if (!function_exists('advanced_woo_discount_rules_get_wholesale_raw_price')) {
    global $awdr_user_wholesale_role;
    function advanced_woo_discount_rules_get_wholesale_raw_price($product_price, $product, $quantity, $cart_item, $calculate_discount_from) {
		global $awdr_user_wholesale_role;
        if (empty($cart_item)) {
			if (is_null($awdr_user_wholesale_role) && class_exists('WWP_Wholesale_Roles') && method_exists('WWP_Wholesale_Roles', 'getInstance')) {
                if (method_exists(\WWP_Wholesale_Roles::getInstance(), 'getUserWholesaleRole')) {
                    $awdr_user_wholesale_role = \WWP_Wholesale_Roles::getInstance()->getUserWholesaleRole();
                }
            }
            if (!empty($awdr_user_wholesale_role) && class_exists('WWP_Wholesale_Prices') && method_exists('WWP_Wholesale_Prices', 'get_product_wholesale_price_on_shop_v3')) {
                $price_data = \WWP_Wholesale_Prices::get_product_wholesale_price_on_shop_v3($product->get_id(), $awdr_user_wholesale_role);
                if (is_array($price_data) && isset($price_data['wholesale_price_raw'])) {
                    $product_price = (float) $price_data['wholesale_price_raw'];
                }
            }
		}
        return $product_price;
    }

    add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', 'advanced_woo_discount_rules_get_wholesale_raw_price', 100, 5);
    add_filter('advanced_woo_discount_rules_product_price_on_before_calculate_discount', 'advanced_woo_discount_rules_get_wholesale_raw_price', 100, 5);
}