在“添加到购物车"操作中更改警报文本,而无需在Woocommerce中进行选择 [英] Change the alert text on add to cart action without selected variation in Woocommerce

查看:100
本文介绍了在“添加到购物车"操作中更改警报文本,而无需在Woocommerce中进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Wordpress中,我正在使用Woocommerce v3.3.5,在可变产品的单个产品页面中,当我单击添加到购物车"按钮而不选择变体选项时,它会弹出一个警告:

in Wordpress I'm using Woocommerce v3.3.5 and in single product pages for variable products, When I click the add to cart button while I don't select a variation option it popups an alert that says :

在将此产品添加到购物车之前,请选择一些产品选项.

Please select some product options before adding this product to your cart.

到目前为止,这是合乎逻辑的..

and that is logical so far ..

我的问题是如何将警报文本更改为适合我业务的其他内容?

My question is How to change the alert text to something else to fit my business?

推荐答案

WooCommerce为发送到JavaScript的所有数据(包括翻译后的文本)提供了过滤器"woocommerce_get_script_data". 因此,这是更改此文本的正确方法:

WooCommerce has a filter "woocommerce_get_script_data" for all data sent to JavaScript including translated texts. So this is the proper way to change this text :

add_filter( 'woocommerce_get_script_data', 'change_alert_text', 10, 2 );
function change_alert_text( $params, $handle ) {
    if ( $handle === 'wc-add-to-cart-variation' )
        $params['i18n_unavailable_text'] = __( 'Your new alert text', 'domain' );

    return $params;
}

如果WooCommerce更改此翻译,则您接受的答案将有问题,您的条件将为假.

If WooCommerce change this translation, you will have a problem with the accepted answer, your condition will be false.

这篇关于在“添加到购物车"操作中更改警报文本,而无需在Woocommerce中进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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