Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在单个产品页面上自定义产品变体消息_Php_Wordpress_Woocommerce_Product_Variations - Fatal编程技术网

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

Php 在单个产品页面上自定义产品变体消息,php,wordpress,woocommerce,product,variations,Php,Wordpress,Woocommerce,Product,Variations,我得到了一个WooCommerce网站,它隐藏了未登录用户的价格,显然它运行良好,除了产品的变化,即使它做了它应该做的事情,也没有正确地做,或者至少不是我会做的方式 我隐藏了可变产品的价格,但允许您选择选项(这很好,这样您可能会鼓励用户注册)。问题是,当您选择完变量后,它会显示以下消息“抱歉,此产品不可用。请选择其他组合”。这是不正确的,这不是一个组合问题,而是一个登录问题。所以我想请求一些关于更改此消息的帮助。作为一个快速提示,我已经在WooCommerce中更改了另一条消息,在child f

我得到了一个WooCommerce网站,它隐藏了未登录用户的价格,显然它运行良好,除了产品的变化,即使它做了它应该做的事情,也没有正确地做,或者至少不是我会做的方式

我隐藏了可变产品的价格,但允许您选择选项(这很好,这样您可能会鼓励用户注册)。问题是,当您选择完变量后,它会显示以下消息“抱歉,此产品不可用。请选择其他组合”。这是不正确的,这不是一个组合问题,而是一个登录问题。所以我想请求一些关于更改此消息的帮助。作为一个快速提示,我已经在WooCommerce中更改了另一条消息,在child 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' );
您可以在此处看到网站的实际行为:

谢谢。

您应该尝试使用将相关邮件替换为自定义邮件的:

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文件中,或位于任何插件文件中。

您应该尝试使用将相关消息替换为自定义消息的:

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函数,可以帮助很多人解决此类问题。谢谢你的夸奖。这只是一个经典的Wordpress功能,在这类问题上帮助了很多人。谢谢你的夸奖。