Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created May 22, 2017 08:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gabrielmerovingi/7e71236a5bd332ee46b307bd2fe58c6a to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/7e71236a5bd332ee46b307bd2fe58c6a to your computer and use it in GitHub Desktop.
Append the product price in points to WooCommerce products.
/**
* Show Cost in Points
* Show the cost of a product in points next to the regular price.
* @version 1.0
*/
function mycred_pro_append_point_price( $rendered_price, $product ) {
if ( $product->get_price() > 0 ) {
$price = $product->get_price();
// How many points does it take to get 1 store currency?
$exchange_rate = 100;
$mycred = mycred();
$rendered_price .= '<small class="point-price">( ' . $mycred->format_creds( $price * $exchange_rate ) . ' )</small>';
}
return $rendered_price;
}
add_filter( 'woocommerce_get_price_html', 'mycred_pro_append_point_price', 10, 2 );
Copy link

ghost commented May 10, 2018

Hi,

How can I change the decimals? To 8 for example. (eg. $1 = 1.00000000 POINT)

@Rage220484
Copy link

Hi,
I used this code to show the points next to the price but I want to hide it in the price range of variable products. How can I do it?
I have managed to hide the price range of the product with this code:

//Remove Price Range
add_filter( 'woocommerce_variable_sale_price_html', 'detect_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'detect_variation_price_format', 10, 2 );

function detect_variation_price_format( $price, $product ) {

// Main Price

$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
if ($prices[0] !== $prices[1] && is_product()) {
$price = $prices[0] !== $prices[1] ? sprintf( __( '', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
}
return $price;
}

But I don't know so much about programing. I'm a designer. Can anybody help me?

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