What can we help you with?

How To Strikeout Regular Price When Role Based Pricing Is Available?

If you are using ELEX WooCommerce Catalog Mode, Wholesale & Role Based Pricing then the below code snippet will help you display regular strikeout price when there is a role-based discount or role-based pricing available. 

 

Consider we have a variable product having 5 variations. The regular price of the variations is 20, 21, 22, 23, 24, and 25 respectively also the assigned Role based prices are 10, 11, 12, 13, 14, and 15. 

 

The prices will be displayed without the code snippet as per the screenshot below.

How To Strikeout Regular Price When Role Based Pricing Is Available?

You can use the code snippet provided below by pasting it to your function.php file from the theme editor to display strike-out regular prices. 

 

add_filter('woocommerce_get_price_html', 'elex_display_striked_out_price_for_variable', 200, 2);

function elex_display_striked_out_price_for_variable($price='', $product)

{

    $reg_price = '';

    if($product->is_type( 'variable' ))

    {

    $variations = $product->get_children();

    $reg_prices = array();

    $sale_prices = array();

    foreach ($variations as $value) {

    $single_variation=new WC_Product_Variation($value);

    $regular_price = get_post_meta($single_variation->get_ID(),'_regular_price',true);

    $sales_price =get_post_meta($single_variation->get_ID(),'_sale_price',true);




    if($single_variation->get_regular_price() == $regular_price ){

        array_push($reg_prices, $single_variation->get_regular_price());

    }else{

        array_push($reg_prices, $regular_price );

    }

    if($single_variation->get_price() == $sales_price ){

        array_push($sale_prices, $sales_price);

    }else{

        array_push($sale_prices, $single_variation->get_price());

    }




    }

    sort($reg_prices);

    sort($sale_prices);

    $reg_min_price = $reg_prices[0];

    $reg_max_price = $reg_prices[count($reg_prices)-1];

    if($reg_min_price == $reg_max_price)

    {

    $reg_price = wc_price($reg_min_price);

    }

    else

    {

    $reg_price = wc_format_price_range($reg_min_price, $reg_max_price);

    }




    $sale_min_price = $sale_prices[0];

    $sale_max_price = $sale_prices[count($sale_prices)-1];

    if($sale_min_price == $sale_max_price)

    {

    $sale_price = wc_price($sale_min_price);

    }

    else

    {

    $sale_price = wc_format_price_range($sale_min_price, $sale_max_price);

    }




    if($reg_min_price == $sale_min_price && $reg_max_price == $sale_max_price ){

        return wc_price($reg_min_price);

    }

    $suffix = $product->get_price_suffix($price);

    return wc_format_sale_price($reg_price, $sale_price).$suffix;

    }

    return $price;

}

After using the code snippet, the prices will be displayed per the screenshot attached below.

How To Strikeout Regular Price When Role Based Pricing Is Available?

More information about the plugin’s features is available on the product page.

For any queries, please contact our support team.

Next Code Snippet for Applying the Role Based Pricing to all the Product Variations
You must be logged in to post a comment.