mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
17 lines
764 B
Text
17 lines
764 B
Text
add_action( 'woocommerce_after_shop_loop_item', 'wc_echo_stock_variations_loop' );
|
|
|
|
function wc_echo_stock_variations_loop(){
|
|
global $product;
|
|
if ( $product->get_type() == 'variable' ) {
|
|
foreach ( $product->get_available_variations() as $key ) {
|
|
$variation = wc_get_product( $key['variation_id'] );
|
|
$stock = $variation->get_availability();
|
|
$stock_string = $stock['availability'] ? $stock['availability'] : __( 'In stock', 'woocommerce' );
|
|
$attr_string = array();
|
|
foreach ( $key['attributes'] as $attr_name => $attr_value ) {
|
|
$attr_string[] = $attr_value;
|
|
}
|
|
echo '<br/>' . implode( ', ', $attr_string ) . ': ' . $stock_string;
|
|
}
|
|
}
|
|
}
|