dragon8899 2016-11-25 19:52
浏览 72
已采纳

通过过滤器自定义WooCommerce请求报价消息

I am trying to customise WooCommerce Request-a-quote plugin, and i cannot get a filter to change. This plugin uses JS Ajax, as well as PHP reload.

This is the code in the plugin file class, which is not within the templates folder:

if ( $return == 'true' ) {
            $message = apply_filters( 'yith_ywraq_product_added_to_list_message', __( 'Product added!', 'yith-woocommerce-request-a-quote' ) );
        }
        elseif ( $return == 'exists' ) {
            $message = apply_filters( 'yith_ywraq_product_already_in_list_message', __( 'Product already in the list.', 'yith-woocommerce-request-a-quote' ) );
        }
        elseif ( count( $errors ) > 0 ) {
            $message = apply_filters( 'yith_ywraq_error_adding_to_list_message', $this->get_errors($errors) );
        }

In the theme function.php, I have put this:

function change_message() {
    $message = 'Enquiry Added!';
    echo apply_filters( 'yith_ywraq_product_already_in_list_message', $message );
}
add_filter('yith_ywraq_error_adding_to_list_message', 'change_message');

But i cannot make it change the text, it remains the same. I do not see what I am missing, can anyone point to it ?

Thanks in advance.

Addy

  • 写回答

1条回答 默认 最新

  • dongyied24121 2016-11-25 20:18
    关注

    You were not to far away, you need to return $message,

     function change_message() {
        $message = 'Enquiry Added!';
    
        return $message;
     }
    
     add_filter('yith_ywraq_error_adding_to_list_message', 'change_message');
    

    Note with this action, you will only change the error message.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)