在单个产品页面上定制产品变化消息 [英] Customizing product variations message on single product pages

查看:79
本文介绍了在单个产品页面上定制产品变化消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WooCommerce网站,该网站隐藏了未登录用户的价格,显然,除了产品变化外,它的工作情况还不错,即使它做了应有的事情,也做得不好,或者至少不是这样做的方式我会的.

I got a WooCommerce website, which hides the prices for not logged in users, and apparently it works fine, except with product variations, that even if it does what it should, is not properly done, or at least not the way I would do it.

我隐藏了变量产品的价格,但允许您选择选项(很好,这样可以鼓励用户注册),问题是当您完成选择变量时,它显示以下消息对不起,此产品不可用.请选择其他组合."这是不正确的,不是组合问题,而是登录问题.因此,我想在更改此消息方面寻求帮助.只是一个简单的提示,在WooCommerce中我已经更改了注释消息,并且在子function.php中有一个函数,请检查下面的代码,您认为我将能够执行类似的操作吗?

I hides the price of the variable product, but allows you to choose options (which is fine, that way you might encourage users to register) the problem is that when you finish choosing the variables, it shows the following message "Sorry, this product is unavailable. Please choose a different combination." Which is incorrect, is not a combination problem, but a login issue. So I wouls like to ask for some help on changing this message. Just as a quick tip, There is anoter message which i have changed already in WooCommerce with a function in the child functions.php, check the code bellow, do you think I will be able to do something similar?

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/

You can see the actual behaviour of the website in here: http://nataliayandres.com/oxynergy/shop/my-personalized-cream/

谢谢.

推荐答案

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

You should try to use the WordPress gettex() function that will replace the concerned message by your custom one:

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文件中,也可能会出现在任何插件文件中.

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

这篇关于在单个产品页面上定制产品变化消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆