在单个产品页面上自定义产品变体消息

Customizing product variations message on single product pages

我有一个 WooCommerce 网站,它隐藏了未登录用户的价格,显然它工作正常,除了产品变体,即使它做了它应该做的,也没有正确完成,或者至少没有我会做的方式。

我隐藏了变量产品的价格,但允许你选择选项(这很好,这样你可能会鼓励用户注册)问题是当你选择完变量时,它会显示以下消息"Sorry, this product is unavailable. Please choose a different combination." 不正确的,不是组合问题,而是登录问题。因此,我想寻求有关更改此消息的帮助。作为一个快速提示,我已经在 WooCommerce 中更改了另一条消息,其中包含一个子函数 functions.php,检查下面的代码,您认为我能做类似的事情吗?

function my_woocommerce_membership_notice( $message ) {
if (strpos($message,'has been removed from your cart because it can no longer be purchased') !== false) {
    $message = 'An item has been removed from your cart as you have been logged out for inactivity. Please login again to add products to your cart.';
}
return $message;
}
add_filter( 'woocommerce_add_error', 'my_woocommerce_membership_notice' );

您可以在此处查看网站的实际行为:http://nataliayandres.com/oxynergy/shop/my-personalized-cream/

谢谢。

您应该尝试使用 WordPress gettex() function,它将用您的自定义消息替换相关消息:

add_filter( 'gettext', 'customizing_product_variation_message', 10, 3 );
function customizing_product_variation_message( $translated_text, $untranslated_text, $domain )
{
    if ($untranslated_text == 'Sorry, this product is unavailable. Please choose a different combination.') {
        $translated_text = __( 'Here goes your custom text', $domain );
    }
    return $translated_text;
}

此代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。