Skip to content

Instantly share code, notes, and snippets.

@aaroncampbell
Created March 27, 2015 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaroncampbell/582fb592c9d31a316473 to your computer and use it in GitHub Desktop.
Save aaroncampbell/582fb592c9d31a316473 to your computer and use it in GitHub Desktop.
Show different strings for stock level of 0, 1, and many items
<?php
$inventory = it_exchange( 'product', 'inventory', 'return=true' );
if ( 0 == $inventory ) {
echo 'Too Late!'; // We're completely out
} elseif ( 1 == $inventory ) {
echo 'There can be only one!'; // There is one in stock
} else {
printf( 'We have %s in stock.', number_format( $inventory, 0, null, ',' ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment