I am trying to understand how to show single and multiple values for my count.
Basically like this:
- "Bought by one customer so far" opposite "Bought by 1 customer so far"
- "Bought by five customers so far" opposite "Bought by 5 customers so far"
How can I convert the total sales number to a word/string?
This is the code I am working with:
add_action( 'woocommerce_single_product_summary', 'product_sold_count', 11 );
add_action( 'woocommerce_after_shop_loop_item', 'product_sold_count', 11 );
function product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->get_id(), 'total_sales', true );
if ($units_sold) echo '<span class="bought-by-customers">' . sprintf( __( 'Bought by %s customers so far', 'woocommerce' ), $units_sold ) . '</span>';
}
Which works, but not the way I prefer it. Any advice?