Skip to content

Instantly share code, notes, and snippets.

@AmeliaBriscoe
Created January 28, 2021 22:46
Show Gist options
  • Save AmeliaBriscoe/253d87da2f42739bdd08e4291af307ef to your computer and use it in GitHub Desktop.
Save AmeliaBriscoe/253d87da2f42739bdd08e4291af307ef to your computer and use it in GitHub Desktop.
Show Unit Stock for Products that have Pre-Orders enabled.
<?php
add_action( 'woocommerce_single_product_summary', 'bbloomer_product_sold_count', 11 );
function bbloomer_product_sold_count() {
global $product;
$units_sold = $product->get_total_sales();
if ( $units_sold && ( 'yes' === $product->get_meta( '_wc_pre_orders_enabled' ) ) ) echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment