发布于 2018-12-15 21:58:30
您可以在的帮助下更改上述文本,而无需修改插件文件“说明什么”插件。按照以下步骤更改文本:
- **Original string:** `You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.`
- **Text domain:** `woocommerce`
- **Text context:**
- **Replacement string:** `You cannot add that amount to the cart — we don't have enough in stock.`
发布于 2018-12-16 04:42:06
这可以在自定义钩子函数中使用gettext筛选器钩子,方法如下:
add_filter( 'gettext', 'custom_add_to_cart_stock_error_notice', 10, 3 );
function custom_add_to_cart_stock_error_notice( $translated, $text, $domain ) {
if ( $text === 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.' && 'woocommerce' === $domain ) {
$translated = __("You cannot add that amount to the cart — we don't have enough in stock.", $domain );
}
return $translated;
}代码在您的活动子主题(或活动主题)的function.php文件中。测试和工作。

发布于 2021-06-27 16:53:50
请注意,@loictheaztec的代码工作正常,但如果要使用数量,则需要在第四行中将引号更改为单引号。
add_filter( 'gettext', 'custom_add_to_cart_stock_error_notice', 10, 3 );
function custom_add_to_cart_stock_error_notice( $translated, $text, $domain ) {
if ( $text === 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.' && 'woocommerce' === $domain ) {
$translated = __('You cannot add that to the cart — we have %1$s in stock and you already have %2$s in your cart.', $domain );
}https://stackoverflow.com/questions/53796760
复制相似问题