在WooCommerce中,我使用的是WooCommerce订阅插件,我正在try 将单个产品页面中的订阅价格字符串中的"每3天"替换为"每周两次".
这是我的代码try :
function replace_single_product_table_text( $content ) {
if ( is_product() ) {
preg_match_all( '/<table[^>]*class="[^"]*shop_table[^"]*"[^>]*>(.*?)<\/table>/s', $content, $matches );
foreach ( $matches[0] as $match ) {
$new_content = str_replace( 'every 3 days', 'Twice a Week', $match );
$new_content = str_replace( '/ week', '/ Week', $new_content );
$new_content = str_replace( 'one a Week', 'Once a Week', $new_content );
$content = str_replace( $match, $new_content, $content );
}
}
return $content;
}
add_filter( 'the_content', 'replace_single_product_table_text', 99 );
不幸的是,它根本不起作用.
任何帮助都将不胜感激.