use wc_format_stock_quantity_for_display() to wrap stock quantity numbers for front end display. closes #12753.

This commit is contained in:
Kathy Darling 2017-01-04 12:24:36 -05:00
parent ec41ba9ff0
commit ff0926aa2d
2 changed files with 15 additions and 5 deletions

View File

@ -490,7 +490,7 @@ class WC_Cart {
*/
if ( ! $product->has_enough_stock( $product_qty_in_cart[ $product->get_stock_managed_by_id() ] ) ) {
/* translators: 1: product name 2: quantity in stock */
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s in stock). Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $product->get_name(), $product->get_stock_quantity() ) );
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s in stock). Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity() ) ) );
return $error;
}
@ -924,7 +924,7 @@ class WC_Cart {
if ( ! $product_data->has_enough_stock( $quantity ) ) {
/* translators: 1: product name 2: quantity in stock */
throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s" to the cart because there is not enough stock (%2$s remaining).', 'woocommerce' ), $product_data->get_name(), $product_data->get_stock_quantity() ) );
throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s" to the cart because there is not enough stock (%2$s remaining).', 'woocommerce' ), $product_data->get_name(), wc_format_stock_quantity_for_display( $product_data->get_stock_quantity() ) ) );
}
// Stock check - this time accounting for whats already in-cart
@ -936,7 +936,7 @@ class WC_Cart {
'<a href="%s" class="button wc-forward">%s</a> %s',
wc_get_cart_url(),
__( 'View Cart', 'woocommerce' ),
sprintf( __( 'You cannot add that amount to the cart &mdash; we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), $product_data->get_stock_quantity(), $products_qty_in_cart[ $product_data->get_id() ] )
sprintf( __( 'You cannot add that amount to the cart &mdash; we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), wc_format_stock_quantity_for_display( $product_data->get_stock_quantity() ), wc_format_stock_quantity_for_display( $products_qty_in_cart[ $product_data->get_id() ] ) )
) );
}
}

View File

@ -933,11 +933,11 @@ function wc_format_stock_for_display( $stock_amount, $show_backorder_notificatio
switch ( get_option( 'woocommerce_stock_format' ) ) {
case 'low_amount' :
if ( $stock_amount <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
$display = sprintf( __( 'Only %s left in stock', 'woocommerce' ), $stock_amount );
$display = sprintf( __( 'Only %s left in stock', 'woocommerce' ), wc_format_stock_quantity_for_display( $stock_amount ) );
}
break;
case '' :
$display = sprintf( __( '%s in stock', 'woocommerce' ), $stock_amount );
$display = sprintf( __( '%s in stock', 'woocommerce' ), wc_format_stock_quantity_for_display( $stock_amount ) );
break;
}
@ -948,6 +948,16 @@ function wc_format_stock_for_display( $stock_amount, $show_backorder_notificatio
return $display;
}
/**
* Format the stock quantity ready for display.
* @since 2.7.0
* @param int $stock_quantity
* @return string
*/
function wc_format_stock_quantity_for_display( $stock_quantity ) {
return apply_filters( 'woocommerce_format_stock_quantity', $stock_quantity );
}
/**
* Format a sale price for display.
* @since 2.7.0