[英]Overriding public functions in jigoshop
I need to override the public function that returns the discount percentage in jigoshop 我需要重写在jigoshop中返回折扣百分比的公共函数
/**
* Returns the products sale value, either with or without a percentage
*
* @return string HTML price of product (with sales)
*/
public function get_calculated_sale_price_html()
{
if ($this->is_on_sale()) {
if (strstr($this->sale_price, '%')) {
return '<del>'.jigoshop_price($this->regular_price).'</del>
<ins>'.jigoshop_price($this->get_price()).'</ins><br/>
<span class="discount">'.sprintf(__('%s off!', 'jigoshop'), $this->sale_price).'</span>';
} else {
return '<del>'.jigoshop_price($this->regular_price).'</del>
<ins>'.jigoshop_price($this->sale_price).'</ins>';
}
}
return '';
}
I tried with 我尝试过
if (!function_exists('calculated_price')) {
function calculated_price(){
if ($this->is_on_sale()) {
if (strstr($this->sale_price, '%')) {
return '<del>'.jigoshop_price($this->regular_price).'</del>
<ins>'.jigoshop_price($this->get_price()).'</ins><br/>
<span class="discount">'.$this->sale_price.'</span>';
} else {
return '<del>'.jigoshop_price($this->regular_price).'</del>
<ins>'.jigoshop_price($this->sale_price).'</ins>';
}
}
return '';
}
}
add_action('get_calculated_sale_price_html', 'calculated_price');
And I tried with add_filter()
but no luck. 我尝试了add_filter()
但没有运气。
Is it possible to modify the existing public function? 是否可以修改现有的公共功能?
For adding your new function, I assume you have a main class that contains your function, so, add a new class that extends that, 为了添加新函数,我假设您有一个包含函数的主类,因此,添加一个扩展该类的新类,
class myclass extends already_externs_class {
function calculated_price(){
}
}
In this case, you have to instantiate from new class that you've written. 在这种情况下,您必须从您编写的新类实例化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.