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 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀