2016-08-23 94 views
0

这是一个price.php文件,用于显示Woocommerce中类别级别的产品价格。它产生的输出如下:编辑Woocommerce get_price_html()格式

₹1504节省66%的捆绑%

<?php if ($price_html = $product->get_price_html()) : ?> 
    <span class="price"><?php echo $price_html; ?></span> 
<?php endif; ?> 

我想编辑的格式,但我不能这样做,我想用₹1504操纵它。如何得到这个?

+0

已经在管理部分中提供了用于更改价格格式的选项。 –

+0

非价格格式我想要使用价格₹1,504 @RaviShankar –

+0

您可以使用“woocommerce_price_html”过滤器钩子进行自定义,请参阅下面的示例代码,这很容易 –

回答

0

请参阅Codex中的add_filter以获取有关将过滤器添加到apply_filters调用的更多信息。

get_price_htmlclass-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); 
} 

欲了解更多信息,请检查该link

请将上面的代码加入您的functions.php

+0

return apply_filters('woocommerce_get_price_html',$ price,$ this);在哪里添加这个? @ purvik7373 –

+0

您不必输入'return apply_filters('woocommerce_get_price_html',$ price,$ this);'。这只是为了你的理解。 – purvik7373

+0

您只需输入'add_filter('woocommerce_get_price_html','custom_price_html',100,2); function custom_price_html($ price,$ product){ return'was:'。 str_replace('','Now:',$ price); }'在你的活动主题'functions.php'文件中。 – purvik7373

0

您也可以使用过滤器挂钩进行更改,请参阅下面的示例代码。

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'); 
+0

在哪里添加此代码?@Ravi Shankar –

+0

下的当前活动主题function.php文件 –