Change the alert text on add to cart action without selected variation in Woocommerce



PHP Snippet 1:

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;
}

PHP Snippet 2:

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['###INSERT YOUR VARIABLE HERE###'] = __( 'Your new alert text', 'domain' );
    return $params;
}

PHP Snippet 3:

add_filter( 'gettext', 'customizing_variable_product_message', 97, 3 );
function customizing_variable_product_message( $translated_text, $untranslated_text, $domain )
{
    if ($untranslated_text == 'Please select some product options before adding this product to your cart.') {
        $translated_text = __( 'Here goes your custom text', $domain );
    }
    return $translated_text;
}

PHP Snippet 4:

add_filter( 'woocommerce_get_script_data', 'change_alert_text', 10, 2 );