I'm simply trying to call one (update post description) if the other signals out of stock. They both work perfectly independently:
function single_product_short_description( $post_excerpt ){
global $product;
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if ( is_single( $product_id ) )
$post_excerpt = '<p class="some-class">' . __( "Out of stock short desc here", "woocommerce" ) . '</p>';
return $post_excerpt;
}
function custom_get_availability( $availability, $_product ) {
global $product, $bar, $progress;
$stock = $product->get_total_stock();
$progress = 100-$stock;
$bar = do_shortcode('[wp_progress_bar text="Tickets Sold - " pc='.$progress.']');
if ( $_product->is_in_stock() ) {
$availability['availability'] = __($bar, 'woocommerce');
}
if ( !$_product->is_in_stock() ) {
add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
}
return $availability;
}
add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
What am I doing wrong?
woocommerce_short_description
you're trying to hook into has already happened when you add that hook inwoocommerce_get_availability
.