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?
Advertisement
Answer
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; }
If WooCommerce change this translation, you will have a problem with the accepted answer, your condition will be false.