Skip to content

Instantly share code, notes, and snippets.

@sirwan
Created August 23, 2018 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirwan/fcc7d370d3fbe5fcd63fe4086dad028e to your computer and use it in GitHub Desktop.
Save sirwan/fcc7d370d3fbe5fcd63fe4086dad028e to your computer and use it in GitHub Desktop.
Change the price formatting
// Check out these two snippets. One for altering the price and the other for altering the price’s html format.
function return_custom_price($price, $product) {
global $post, $blog_id;
$price = get_post_meta($post->ID, '_regular_price');
$post_id = $post->ID;
$price = ($price[0]*2.5);
return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);
// And this for price’s html format.
function cw_change_product_price_display( $price, $product ) {
if ( has_term( 'fabrics', 'product_cat' ) ) {
$price .= ' <span style="color: #ababab; font-weight: 100; font-size: 0.8em;"> per roll</span>';
} elseif ( has_term( 'sofas', 'product_cat' ) ) {
$price .= ' <span style="color: #ababab; font-weight: 100;">per sofa</span>';
} else {
echo 'test';
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment