【发布时间】:2021-08-03 15:01:54
【问题描述】:
尝试从 Woocommerce 注释的内容中提取运输跟踪号给客户,最终将其作为值传递给自定义字段
原函数
function get_value( $comment, $parameters ) {
return $comment->content;
}
修改功能(不工作)
function get_value( $comment, $parameters ) {
$tracking_note = $comment->content;
$new_output = preg_replace( '/[^0-9]/', '', $tracking_note );
return $new_output->content;
}
【问题讨论】:
-
为什么你认为 preg_replace 返回一个对象?你有没有尝试访问php.net阅读功能描述?
-
该函数可以只返回变量,如:
return $new_output;。这行得通吗? -
@GerarddeVisser 谢谢,这就是我所需要的。
-
@user2059376 这很好用。我已将此添加为答案,以供其他寻求此解决方案的人参考。随意接受/支持答案。
标签: php woocommerce preg-replace