如何仅通过 child 主题函数更改 'apply_filters' 的值?
How to only change the value from 'apply_filters' via child theme functions?
我有以下代码在我想删除的电子邮件的订单摘要中输出文本“via nameOfshippingMethod”:
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_shipped_via', ' <small class="shipped_via">' . sprintf( __( 'via %s', 'woocommerce' ), $this->get_shipping_method() ) . '</small>', $this );
从采取侵入性最小的方法的角度来看,是否可以以某种方式更改此 apply_filters
的值,或者我是否必须替换 child [=28= 中的整个函数]?
如果有人能帮助我,我将不胜感激!
为了完整起见,整个函数是(位于“abstract-wc-order.php):
public function get_shipping_to_display( $tax_display = '' ) {
$tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
if ( 0 < abs( (float) $this->get_shipping_total() ) ) {
if ( 'excl' === $tax_display ) {
// Show shipping excluding tax.
$shipping = wc_price( $this->get_shipping_total(), array( 'currency' => $this->get_currency() ) );
if ( (float) $this->get_shipping_tax() > 0 && $this->get_prices_include_tax() ) {
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>', $this, $tax_display );
}
} else {
// Show shipping including tax.
$shipping = wc_price( $this->get_shipping_total() + $this->get_shipping_tax(), array( 'currency' => $this->get_currency() ) );
if ( (float) $this->get_shipping_tax() > 0 && ! $this->get_prices_include_tax() ) {
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>', $this, $tax_display );
}
}
/* translators: %s: method */
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_shipped_via', ' <small class="shipped_via">' . sprintf( __( 'via %s', 'woocommerce' ), $this->get_shipping_method() ) . '</small>', $this );
} elseif ( $this->get_shipping_method() ) {
$shipping = $this->get_shipping_method();
} else {
$shipping = __( 'Free!', 'woocommerce' );
}
return apply_filters( 'woocommerce_order_shipping_to_display', $shipping, $this, $tax_display );
}
借助 Howard E 的有用提示,我能够生成以下有效的 WooCommerce 过滤器:
add_filter( 'woocommerce_order_shipping_to_display_shipped_via', 'woocommerce_order_shipping_to_display_shipped_via_remove', 10);
function woocommerce_order_shipping_to_display_shipped_via_remove( $no_via ) {
$no_via = ' <small class="shipped_via"></small>' ;
return $no_via;
}
这对第一次创建它很有帮助:
https://www.hardworkingnerd.com/how-to-use-add_filter-and-apply_filters-in-woocommerce/
我有以下代码在我想删除的电子邮件的订单摘要中输出文本“via nameOfshippingMethod”:
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_shipped_via', ' <small class="shipped_via">' . sprintf( __( 'via %s', 'woocommerce' ), $this->get_shipping_method() ) . '</small>', $this );
从采取侵入性最小的方法的角度来看,是否可以以某种方式更改此 apply_filters
的值,或者我是否必须替换 child [=28= 中的整个函数]?
如果有人能帮助我,我将不胜感激!
为了完整起见,整个函数是(位于“abstract-wc-order.php):
public function get_shipping_to_display( $tax_display = '' ) {
$tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
if ( 0 < abs( (float) $this->get_shipping_total() ) ) {
if ( 'excl' === $tax_display ) {
// Show shipping excluding tax.
$shipping = wc_price( $this->get_shipping_total(), array( 'currency' => $this->get_currency() ) );
if ( (float) $this->get_shipping_tax() > 0 && $this->get_prices_include_tax() ) {
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>', $this, $tax_display );
}
} else {
// Show shipping including tax.
$shipping = wc_price( $this->get_shipping_total() + $this->get_shipping_tax(), array( 'currency' => $this->get_currency() ) );
if ( (float) $this->get_shipping_tax() > 0 && ! $this->get_prices_include_tax() ) {
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>', $this, $tax_display );
}
}
/* translators: %s: method */
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_shipped_via', ' <small class="shipped_via">' . sprintf( __( 'via %s', 'woocommerce' ), $this->get_shipping_method() ) . '</small>', $this );
} elseif ( $this->get_shipping_method() ) {
$shipping = $this->get_shipping_method();
} else {
$shipping = __( 'Free!', 'woocommerce' );
}
return apply_filters( 'woocommerce_order_shipping_to_display', $shipping, $this, $tax_display );
}
借助 Howard E 的有用提示,我能够生成以下有效的 WooCommerce 过滤器:
add_filter( 'woocommerce_order_shipping_to_display_shipped_via', 'woocommerce_order_shipping_to_display_shipped_via_remove', 10);
function woocommerce_order_shipping_to_display_shipped_via_remove( $no_via ) {
$no_via = ' <small class="shipped_via"></small>' ;
return $no_via;
}
这对第一次创建它很有帮助: https://www.hardworkingnerd.com/how-to-use-add_filter-and-apply_filters-in-woocommerce/