Improved message when variation attributes are missing.

Closes #7670
This commit is contained in:
Mike Jolley 2015-03-09 13:12:11 +00:00
parent ca6e9a7371
commit 5cbd02fef2
3 changed files with 23 additions and 17 deletions

View File

@ -593,17 +593,10 @@ class WC_Form_Handler {
$variation_id = empty( $_REQUEST['variation_id'] ) ? '' : absint( $_REQUEST['variation_id'] );
$quantity = empty( $_REQUEST['quantity'] ) ? 1 : wc_stock_amount( $_REQUEST['quantity'] );
$all_variations_set = true;
$missing_attributes = array();
$variations = array();
// Only allow integer variation ID - if its not set, redirect to the product page
if ( empty( $variation_id ) ) {
wc_add_notice( __( 'Please choose product options…', 'woocommerce' ), 'error' );
return;
}
$attributes = $adding_to_cart->get_attributes();
$variation = wc_get_product( $variation_id );
$attributes = $adding_to_cart->get_attributes();
$variation = wc_get_product( $variation_id );
// Verify all attributes
foreach ( $attributes as $attribute ) {
@ -641,12 +634,18 @@ class WC_Form_Handler {
continue;
}
} else {
$missing_attributes[] = wc_attribute_label( $attribute['name'] );
}
$all_variations_set = false;
}
if ( $all_variations_set ) {
if ( $missing_attributes ) {
wc_add_notice( sprintf( _n( '%s is a required field', '%s are required fields', sizeof( $missing_attributes ), 'woocommerce' ), wc_format_list_of_items( $missing_attributes ) ), 'error' );
return;
} elseif ( empty( $variation_id ) ) {
wc_add_notice( __( 'Please choose product options…', 'woocommerce' ), 'error' );
return;
} else {
// Add to cart validation
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations );
@ -657,9 +656,6 @@ class WC_Form_Handler {
$added_to_cart[] = $product_id;
}
}
} else {
wc_add_notice( __( 'Please choose product options…', 'woocommerce' ), 'error' );
return;
}
// Grouped Products

View File

@ -73,7 +73,7 @@ function wc_add_to_cart_message( $product_id ) {
$titles[] = get_the_title( $id );
}
$added_text = sprintf( __( 'Added "%s" to your cart.', 'woocommerce' ), join( __( '" and "', 'woocommerce' ), array_filter( array_merge( array( join( '", "', array_slice( $titles, 0, -1 ) ) ), array_slice( $titles, -1 ) ) ) ) );
$added_text = sprintf( __( 'Added %s to your cart.', 'woocommerce' ), wc_format_list_of_items( $titles ) );
} else {
$added_text = sprintf( __( '"%s" was successfully added to your cart.', 'woocommerce' ), get_the_title( $product_id ) );
@ -95,6 +95,15 @@ function wc_add_to_cart_message( $product_id ) {
wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );
}
/**
* Comma separate a list of item names, and replace final comma with 'and'
* @param array $items
* @return string
*/
function wc_format_list_of_items( $items ) {
return '"' . join( __( '" and "', 'woocommerce' ), array_filter( array_merge( array( implode( '", "', array_slice( $items, 0, -1 ) ) ), array_slice( $items, -1 ) ) ) ) . '"';
}
/**
* Clear cart after payment.
*

View File

@ -152,6 +152,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - Shipping calculator - Made state/postcode respect country locale like checkout.
* Tweak - Move default customer location to general settings tab.
* Tweak - Only run save_category_fields for product_cat taxonomy.
* Tweak - Improved message when variation attributes are missing.
= 2.3.5 - 20/02/2015 =
* Fix - Plain text address formatting.