Created
July 18, 2014 14:51
-
-
Save Jeff2Ma/91c6f19ab63552be269c to your computer and use it in GitHub Desktop.
change woocommerce defalut price html code
This file contains 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
<?php | |
// DeveWork.com | |
//这是一个可以修改woocommerce_get_price_html 函数默认输出的html代码的例子, | |
//作用是调换新旧价格的位置 | |
//感谢http://wordpress.stackexchange.com/questions/83367/how-to-edit-the-get-price-html-on-woocommerce | |
add_filter( 'woocommerce_get_price_html', 'dw_change_default_price_html', 100, 2 ); | |
function dw_change_default_price_html( $price,$product ){ | |
if ( $product->price > 0 ) { | |
if ( $product->price && isset( $product->regular_price ) ) { | |
$from = $product->regular_price; | |
$to = $product->price; | |
return '<ins><span class="amount">'.( ( is_numeric( $to ) ) ? woocommerce_price( $to ) : $to ) .'</span></ins> | |
<del><span class="amount">'. ( ( is_numeric( $from ) ) ? woocommerce_price( $from ) : $from ) .' </span></del>'; | |
} else { | |
$to = $product->price; | |
return '<ins><span class="amount">' . ( ( is_numeric( $to ) ) ? woocommerce_price( $to ) : $to ) . '</span></ins>'; | |
} | |
} else { | |
return '免费'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change
$product->price && isset( $product->regular_price
to$product->price and $product->sale_price