Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created March 20, 2018 13:25
Show Gist options
  • Save Garconis/9ea3f3bdf5bffa09b48239df02ffa7dc to your computer and use it in GitHub Desktop.
Save Garconis/9ea3f3bdf5bffa09b48239df02ffa7dc to your computer and use it in GitHub Desktop.
WooCommerce | Output a list of product attribute terms for a specific attribute
<?php
add_shortcode( 'fs-product-special-features', 'fs_product_special_features_img_shortcode' );
function fs_product_special_features_img_shortcode( $atts ) {
// begin output buffering
ob_start();
// grab the terms of the product's attribute
$special_feature_terms = get_the_terms($post->ID, 'pa_special-features');
//$count = count($special_feature_terms);
if ( ! empty( $special_feature_terms ) && ! is_wp_error( $special_feature_terms ) ){
echo '<ul class="fs-special-features">';
foreach ( $special_feature_terms as $special_feature_term ) {
echo '<li class="fs-special-features-'. $special_feature_term->slug .'" title="' . $special_feature_term->name . '">' . $special_feature_term->name . '</li>';
}
echo '</ul>';
}
// end output buffering, grab the buffer contents, and empty the buffer
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment