【发布时间】:2021-10-15 21:51:08
【问题描述】:
我正在尝试有条件地更改 WooCommerce 我的帐户端点上的字符串。每次我尝试添加端点条件时,它要么破坏站点,要么不起作用;但是,当我不使用条件时,字符串替换有效。也许有人可以指出我哪里出错了。
工作片段 - 无条件
function change_endpoint_text( $translated ) {
$translated = str_ireplace( 'List of coupons which are valid & available for use. Click on the coupon to use it. The coupon discount will be visible only when at least one product is present in the cart.', 'List of vouchers which are valid & available for use. Click on a voucher to use it. The discount will be visible only when at least one product is present in the cart.', $translated );
return $translated;
}
add_filter( 'gettext', 'change_endpoint_text' );
条件片段测试 - 不工作
注意:我还尝试使用似乎会破坏网站的 is_account_page 条件。
function change_endpoint_text( $translated ) {
if( is_wc_endpoint_url('wc-smart-coupons') ) {
$translated = str_ireplace( 'List of coupons which are valid & available for use. Click on the coupon to use it. The coupon discount will be visible only when at least one product is present in the cart.', 'List of vouchers which are valid & available for use. Click on a voucher to use it. The discount will be visible only when at least one product is present in the cart.', $translated );
}
return $translated;
}
add_filter( 'gettext', 'change_endpoint_text' );
任何帮助将不胜感激。
【问题讨论】:
-
澄清一下,您到底想使用
is_wc_endpoint_url检查什么?wc-smart-coupons来自哪里?你在使用第三方插件吗? -
@Ruvee - 我正在尝试检查我是否在特定端点上,如果我在然后继续翻译。在我的示例中,端点
wc-smart-coupons来自 WooCommerce 智能优惠券插件,但这仅适用于那个字符串。如果我可以成功地定位任何端点上的字符串,那么我也可以更改其他区域的消息。如edit-adressess端点上的“默认情况下将在结帐页面上使用以下地址”文本示例。我不确定我是否过于复杂或诚实地做错了。 -
这就是我的想法,您使用的是第三方插件。这个插件是否注册了额外的端点?我认为
is_wc_endpoint_url仅识别在 woocommerce 设置中找到的 woocommerce 默认端点。wc-smart-coupons是一个单独的页面还是只是一个query variable? -
@Ruvee - 啊啊啊。我没有意识到它只会识别默认端点。它是一个单独的“页面”,就像您看到任何其他端点(即下载、地址等)的方式一样。
标签: php wordpress woocommerce gettext