Created
August 23, 2018 03:03
-
-
Save sirwan/fcc7d370d3fbe5fcd63fe4086dad028e to your computer and use it in GitHub Desktop.
Change the price formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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