Php 编辑Woocommerce get_price_html()格式
这是一个price.php文件,用于显示Woocommerce中类别级别的产品价格。它产生以下输出: ₹1504每包节省66%Php 编辑Woocommerce get_price_html()格式,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,这是一个price.php文件,用于显示Woocommerce中类别级别的产品价格。它产生以下输出: ₹1504每包节省66% 我想编辑格式,但我无法编辑我想使用的格式₹1504来操纵它。如何获取此信息?有关在通话中添加筛选器的更多信息,请参见法典 从class wc product中的get\u price\u html: return apply_filters('woocommerce_get_price_html', $price, $this); 因此,要添加您自己的过滤器: a
我想编辑格式,但我无法编辑我想使用的格式₹1504来操纵它。如何获取此信息?有关在通话中添加筛选器的更多信息,请参见法典
从class wc product
中的get\u price\u html
:
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 );
}
add_filter('woocommerce_get_price_html','custom_price_html',100,2);
函数自定义\价格\ html($price,$product){
返回“Was:”.str_replace(“”,“Now:”,$price);
}
有关更多信息,请查看此项
请在
函数中添加上述代码。php
?您也可以使用过滤器挂钩进行更改,请参见下面的示例代码
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' );
function cs\u custom\u simple\u product\u price\u html($price){
全球$产品;
$parcels=10;//在此处编辑包裹数!
$parcel\U price=$product->get\U price()/10;
$html='.$parcels.x';
$html.=woocmerce_price($packet_price)。“
”;
$html.=''。uu('sem juros')。
;
$html.=woocommerce\u price($product->get\u price());
返回$html;
}
添加过滤器(“woocommerce\u price\u html”、“cs\u custom\u simple\u product\u price\u html”);
管理部分已经提供了更改价格格式的选项。您尝试过了吗。不是价格格式我想使用价格₹1504@ravishankary您可以使用“woocommerce\u price\u html”过滤器挂钩进行自定义,请参见下面的示例代码,在当前活动的主题函数下很容易实现。php filereturn apply\u filters('woocommerce\u get\u price\u html',$price,$this);在哪里添加这个@purvik7373您不必输入返回应用过滤器('woocommerce\u get\u price\u html',$price,$this)代码>。您只需输入add_filter('woocommerce_get_price_html','custom_price_html',100,2);函数custom_price_html($price,$product){return'是:'.str_replace(''Now:',$price)}
在活动主题functions.php
文件中。当我在functions.php中添加代码时,它会更改我的₹1504每包节省66%,但我不想改变,我只想从中提取$price并在purvik7373处操纵它
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' );