这是一个price.php文件,用于在Woocommerce中显示产品类别级别的价格。它产生以下输出:
₹1,504每束节省66%
<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>
我想编辑格式,但我不能这样做,我想使用₹1,504来操纵它。怎么弄到这个?
发布于 2016-08-23 06:58:10
有关向过滤器调用添加筛选器的更多信息,请参见代码法典中的过滤器。
来自get_price_html
in class-wc-product
return apply_filters('woocommerce_get_price_html', $price, $this);
因此,要添加您自己的过滤器:
add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
function custom_price_html( $price, $product ){
return 'Was:' . str_replace( '<ins>', ' Now:<ins>', $price );
}
有关更多信息,请查看此链接。
请您在您的functions.php
中添加上述代码
发布于 2016-08-23 07:00:30
您也可以通过使用过滤器挂钩进行更改,参见下面的示例代码。
function cs_custom_simple_product_price_html( $price ) {
global $product;
$parcels = 10; // Edit the number of parcels here!
$parcel_price = $product->get_price() / 10;
$html = '<span class="parcels">' . $parcels . 'x </span>';
$html .= woocommerce_price( $parcel_price ) . '<br />';
$html .= '<span class="without-interest">' . __( 'sem juros' ) . '</span><br />';
$html .= woocommerce_price( $product->get_price() );
return $html;
}
add_filter( 'woocommerce_price_html', 'cs_custom_simple_product_price_html' );
https://stackoverflow.com/questions/39094195
复制相似问题