【发布时间】:2017-05-09 17:00:05
【问题描述】:
有人可以建议我如何通过 WooCommerce 中单个产品变体描述的操作或过滤器(或操作标记)来进行 PHP 字符串替换吗?
似乎没有任何挂钩。
以上是为了让我可以将描述的每个换行符变成一个列表项。
【问题讨论】:
标签: php wordpress woocommerce product variations
有人可以建议我如何通过 WooCommerce 中单个产品变体描述的操作或过滤器(或操作标记)来进行 PHP 字符串替换吗?
似乎没有任何挂钩。
以上是为了让我可以将描述的每个换行符变成一个列表项。
【问题讨论】:
标签: php wordpress woocommerce product variations
您可以尝试在自定义挂钩函数中使用 Wordpress 专用的 gettex 挂钩,这样:
add_filter('gettext', 'wc_custom_renaming', 10, 3);
function wc_custom_renaming( $replaced_text, $source_text, $domain ) {
// only for single product pages
if( is_product() ) {
// Set here the complete description to be replaced
if( $source_text == 'The text to replace' ){
// Set here your replacement description
$replaced_text = __( 'Your new text',$domain );
}
}
return $replaced_text;
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
这仅在您替换完整描述时才有效。如果您只想替换一个单词或一个子字符串,您需要使用
strpos()和str_replace()php 函数进一步自定义此函数...
【讨论】: