Php 如何替换单个产品变体描述中的字符串?
有人能告诉我如何通过WooCommerce中单个产品变体描述的操作或过滤器(或操作标记)来进行PHP字符串替换吗 这似乎没有任何挂钩Php 如何替换单个产品变体描述中的字符串?,php,wordpress,woocommerce,product,variations,Php,Wordpress,Woocommerce,Product,Variations,有人能告诉我如何通过WooCommerce中单个产品变体描述的操作或过滤器(或操作标记)来进行PHP字符串替换吗 这似乎没有任何挂钩 上面是这样,我可以将描述的每一行都转换为一个列表项。您可以尝试在自定义挂钩函数中使用Wordpress专用挂钩,方法如下: add_filter('gettext', 'wc_custom_renaming', 10, 3); function wc_custom_renaming( $replaced_text, $source_text, $domain )
上面是这样,我可以将描述的每一行都转换为一个列表项。您可以尝试在自定义挂钩函数中使用Wordpress专用挂钩,方法如下:
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()
和stru replace()
php函数进一步自定义此函数,例如
谢谢,我不知道这个过滤器。我需要它专门针对产品变体的描述,并用“