【问题标题】:WooCommerce override functionWooCommerce 覆盖功能
【发布时间】:2016-10-20 00:24:59
【问题描述】:
我想覆盖 woocommerce 中的一个函数,特别是 -
woocommerce/includes/wc-cart-functions.php(wc_cart_totals_order_total_html 函数)。
我可以直接编辑该函数(它会输出需要更改的 html),但我不希望这样做,因为我会丢失更新时的更改。
我确定这是很常见的事情,我只是不太确定如何去做。如果我将函数复制到主题中的functions.php,我会收到关于重新声明函数的错误。
【问题讨论】:
标签:
wordpress
woocommerce
【解决方案1】:
这是一个古老的话题,但也许我可以提供一点帮助。我有类似的问题。我想覆盖货币,并添加自定义货币。函数位于 woocommerce/includes/wc-core-functions.php
function get_woocommerce_currencies() {
return array_unique(
apply_filters( 'woocommerce_currencies',
array(
另一个函数是:
function get_woocommerce_currency_symbol( $currency = '' ) {
if ( ! $currency ) {
$currency = get_woocommerce_currency();
}
switch ( $currency ) {
...
return apply_filters( 'woocommerce_currency_symbol', $currency_symbol, $currency );
这是我在我的子主题的functions.php中放入的代码:
add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
$currencies['RSD'] = __( 'Serbian dinar', 'woocommerce' );
return $currencies;
}