繁体   English   中英

在jigoshop中重写公共功能

[英]Overriding public functions 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 '';
}

我尝试过

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

我尝试了add_filter()但没有运气。

是否可以修改现有的公共功能?

为了添加新函数,我假设您有一个包含函数的主类,因此,添加一个扩展该类的新类,

class myclass extends already_externs_class {
        function calculated_price(){
        }
}

在这种情况下,您必须从您编写的新类实例化。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM