One of the UK’s leading craft beer distributors

Stock Counts

$week_num,
‘start’ => date( ‘Y-m-d 00:00:00’, $iter ),
‘end’ => date( ‘Y-m-d 23:59:59’, $week_end ),
‘label’ => ‘Wk ‘ . $week_num . ‘ (‘ . date( ‘d/m’, $iter ) . ‘)’,
‘quarter’ => ceil( $week_num / 13.0 )
);
$iter += ( 86400 * 7 );
$week_num++;
}

return $weeks;
}

/**
* Shortcode callback
*/
add_shortcode( ‘stock_counts’, __NAMESPACE__ . ‘\render_stock_counts_5d204db3’ );
function render_stock_counts_5d204db3() {
$selected_format = isset( $_GET[‘st_format’] ) ? sanitize_text_field( $_GET[‘st_format’] ) : ‘all’;
$selected_style = isset( $_GET[‘st_style’] ) ? sanitize_text_field( $_GET[‘st_style’] ) : ”;

$styles_by_format = array(
‘Can’ => array( ‘Bitter • Mild’, ‘Brown Ale’, ‘DIPA • TIPA • QIPA’, ‘Gluten Free’, ‘Gold • Amber • Blonde • Red’, ‘IPA’, ‘Lager • Pilsner’, ‘NoLo’, ‘Pale Ale’, ‘Sour’, ‘Stout • Porter’, ‘Table Beer’, ‘Wheat • Misc’ ),
‘Cask’ => array( ‘Bitter • Mild’, ‘Brown Ale’, ‘DIPA • TIPA • QIPA’, ‘Gluten Free’, ‘Gold • Amber • Blonde • Red’, ‘IPA’, ‘Lager • Pilsner’, ‘NoLo’, ‘Pale Ale’, ‘Sour’, ‘Stout • Porter’, ‘Table Beer’, ‘Wheat • Misc’ ),
‘Keg’ => array( ‘Bitter • Mild’, ‘Brown Ale’, ‘DIPA • TIPA • QIPA’, ‘Gluten Free’, ‘Gold • Amber • Blonde • Red’, ‘IPA’, ‘Lager • Pilsner’, ‘NoLo’, ‘Pale Ale’, ‘Sour’, ‘Stout • Porter’, ‘Table Beer’, ‘Wheat • Misc’ ),
‘Cider’ => array( ‘Cider BIB’, ‘Cider Can’, ‘Cider Case’, ‘Cider Keg’ )
);

$formats = array_keys( $styles_by_format );
$tax_query = array( ‘relation’ => ‘AND’ );

if ( $selected_format !== ‘all’ ) {
$tax_query[] = array(
‘taxonomy’ => ‘product_tag’,
‘field’ => ‘name’,
‘terms’ => $selected_format,
);
}
if ( ! empty( $selected_style ) ) {
$tax_query[] = array(
‘taxonomy’ => ‘product_tag’,
‘field’ => ‘name’,
‘terms’ => $selected_style,
);
}

$args = array(
‘post_type’ => ‘product’,
‘posts_per_page’ => -1,
‘tax_query’ => count( $tax_query ) > 1 ? $tax_query : ”,
);

$products = get_posts( $args );
$total_skus = 0;
$total_stock_qty = 0;

foreach ( $products as $p ) {
$product = wc_get_product( $p->ID );
if ( $product && $product->is_in_stock() ) {
$total_skus++;
$total_stock_qty += max( 0, (float) $product->get_stock_quantity() );
}
}

$weeks = get_sales_weeks_5d204db3();
$sales_data = array_fill_keys( array_keys( $weeks ), 0 );

if ( function_exists( ‘wc_get_orders’ ) ) {
$orders = wc_get_orders( array(
‘status’ => array( ‘completed’, ‘processing’ ),
‘date_created’ => ‘2026-04-01…2027-12-31’,
‘limit’ => -1,
) );

foreach ( $orders as $order ) {
$order_date = $order->get_date_created()->date( ‘Y-m-d H:i:s’ );
foreach ( $order->get_items() as $item ) {
$prod = $item->get_product();
if ( ! $prod ) continue;
$tags = wp_get_post_terms( $prod->get_id(), ‘product_tag’, array( ‘fields’ => ‘names’ ) );
$format_match = ( $selected_format === ‘all’ ) || in_array( $selected_format, $tags );
$style_match = empty( $selected_style ) || in_array( $selected_style, $tags );

if ( $format_match && $style_match ) {
foreach ( $weeks as $w_idx => $w_info ) {
if ( $order_date >= $w_info[‘start’] && $order_date <= $w_info['end'] ) { $sales_data[ $w_idx ] += $item->get_quantity();
break;
}
}
}
}
}
}

$quarter_totals = array( 1 => 0, 2 => 0, 3 => 0, 4 => 0 );
$quarter_counts = array( 1 => 0, 2 => 0, 3 => 0, 4 => 0 );

foreach ( $weeks as $w_idx => $w_info ) {
$q = $w_info[‘quarter’];
if ( isset( $quarter_totals[ $q ] ) ) {
$quarter_totals[ $q ] += $sales_data[ $w_idx ];
$quarter_counts[ $q ]++;
}
}

$qa_averages = array();
foreach ( $quarter_totals as $q => $total ) {
$count = $quarter_counts[ $q ];
$qa_averages[ $q ] = $count > 0 ? ( $total / $count ) : 0.0;
}

$performance_indicators = array();
for ( $q = 1; $q <= 4; $q++ ) { if ( $q === 1 ) { $performance_indicators[ $q ] = '‘;
} else {
$prev = $qa_averages[ $q – 1 ];
$curr = $qa_averages[ $q ];
if ( $prev > 0 ) {
$growth = ( ( $curr – $prev ) / $prev ) * 100;
if ( $growth > 0 ) {
$performance_indicators[ $q ] = ‘▲ ‘ . number_format( $growth, 1 ) . ‘%‘;
} elseif ( $growth < 0 ) { $performance_indicators[ $q ] = '▼ ‘ . number_format( abs($growth), 1 ) . ‘%‘;
} else {
$performance_indicators[ $q ] = ‘= 0%‘;
}
} else {
$performance_indicators[ $q ] = $curr > 0 ? ‘▲ New‘ : ‘‘;
}
}
}

ob_start();
?>

‘all’, ‘st_style’ => ” ) );
?>
” class=”stock-tab-btn-5d204db3“>


In-Stock SKUs / Choice

Total Stock Quantity

$w_info ) : ?>


$w_info ) : ?>


Metric / Week
Sales Quantity