【问题标题】:How do I edit default message in Woocommerce?如何在 Woocommerce 中编辑默认消息?
【发布时间】:2019-10-24 17:28:23
【问题描述】:

我想编辑 woocommerce 中的默认消息,因为它们是英文的,我希望它们是法文的。 例如,我想在插件预订表单中编辑此消息:

$booking_form_params = array(
  ....
            'i18n_choose_options'        => __( 'Please select the options for your booking and make sure duration rules apply.', 'woocommerce-bookings' ),

另外,在这个函数中有:

        wp_localize_script( 'wc-bookings-booking-form', 'booking_form_params', apply_filters( 'booking_form_params', $booking_form_params ) );

我想我必须使用add_filter,但我不知道我必须使用哪个参数。

【问题讨论】:

标签: php wordpress function woocommerce filter


【解决方案1】:

您可以在functions.php或任何相关文件中添加以下代码:

add_filter( 'woocommerce_cart_no_shipping_available_html', 'change_msg_no_available_shipping_methods', 10, 1  );
add_filter( 'woocommerce_no_shipping_available_html', 'change_msg_no_available_shipping_methods', 10, 1 );
function change_msg_no_available_shipping_methods( $default_msg ) {
    $custom_msg = "Call us for quotation - 1-800-XXX-XXXX";
    if( empty( $custom_msg ) ) {
      return $default_msg;
    }

    return $custom_msg;
}

仅供您理解,您可以根据自己的需要进行修改

【讨论】:

  • 谢谢,我只是想知道你从哪里得到 'woocommerce_cart_no_shipping_available_html'
  • cart-shipping.php
【解决方案2】:

如果需要,这里是解决方案:

add_filter( 'booking_form_params', 'change_msg2',  10, 1  );
function change_msg2( $default_msg ) {
    $default_msg['i18n_choose_options' ] = 'Your new message';

    return $default_msg;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 2012-09-26
    • 2021-10-11
    • 2014-11-10
    • 2023-04-02
    相关资源
    最近更新 更多