Skip to content

Instantly share code, notes, and snippets.

@blivic
Last active June 20, 2019 15:12
Show Gist options
  • Save blivic/0be09145a44e029bb8f107b78a78fe2e to your computer and use it in GitHub Desktop.
Save blivic/0be09145a44e029bb8f107b78a78fe2e to your computer and use it in GitHub Desktop.
Display available sizes on shop page
<?php
/**
* DO NOT copy the opening php tag
* check if you're using the correct attribute slug
*/
add_action('woocommerce_after_shop_loop_item','display_size_attribute_in_shop');
function display_size_attribute_in_shop() {
global $product;
if( $product->is_type('variable') ){
$color_val = $product->get_attribute('pa_size');
if( ! empty($color_val) ){
echo "<div class='size_att'>";
echo "<span>In sizes: </span>";
echo $color_val;
echo "</div";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment