Skip to content

Instantly share code, notes, and snippets.

@byronrode
Created August 29, 2015 11:39
Show Gist options
  • Save byronrode/26b4fd82f4dc42c038e0 to your computer and use it in GitHub Desktop.
Save byronrode/26b4fd82f4dc42c038e0 to your computer and use it in GitHub Desktop.
Add <sup></sup> wrapper around decimals for WooCommerce prices.
<?php
add_filter( 'woocommerce_get_price_html', 'themeprefix_add_sup_decimals_to_pricing' );
if(!function_exists( 'themeprefix_add_sup_decimals_to_pricing' )){
function themeprefix_add_sup_decimals_to_pricing( $price )
{
if(!is_admin()){ // Check that we're not in the admin
$price = strip_tags($price);
$price_exploded = explode('&ndash;', $price);
if(count($price_exploded) > 1) { // Variable Pricing
$_price = '';
$count = 0;
foreach($price_exploded as $p_e){
$new_pe = explode('.', $p_e);
$_price .= '<span class="amount">' . $new_pe[0] . '<sup>.' . $new_pe[1] . '</sup></span>';
if($count < 1)
$_price .= '&mdash;';
$count++;
}
return $_price;
}else{ // Simple Product Pricing
$price_exploded = explode('.', $price);
return '<span class="amount">' . $price_exploded[0] . '<sup>.' . $price_exploded[1] . '</sup></span>';
}
}else{
return $price;
}
}
}
@bosakoo
Copy link

bosakoo commented Jun 30, 2017

Hi, how can i change this code so that currency_symbol was not in </ sup>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment