【问题标题】:Customizing product variations message on single product pages在单个产品页面上自定义产品变体消息
【发布时间】:2016-10-02 18:03:07
【问题描述】:

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

我隐藏了变量产品的价格,但允许您选择选项(这很好,这样您可能会鼓励用户注册)问题是当您完成选择变量时,它会显示以下消息“对不起, 此产品不可用。请选择其他组合。”哪个不正确,不是组合问题,而是登录问题。因此,我想就更改此消息寻求一些帮助。作为一个快速提示,我已经在 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/

谢谢。

【问题讨论】:

    标签: php wordpress woocommerce product variations


    【解决方案1】:

    您应该尝试使用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 文件中或任何插件文件中。

    【讨论】:

    • 它只是一个经典的 Wordpress 功能,在这类问题上帮助了很多人。谢谢夸奖。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-30
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多