-
-
Save klikdiva/7a70fc189c969c9d06d4e4c303403d67 to your computer and use it in GitHub Desktop.
Add WooCommerce product meta to the shop loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Will add information to the shop loop above the "Add to cart" button | |
* This example will use post meta (custom fields) and display them if set | |
* Tutorial: http://www.skyverge.com/blog/add-information-to-woocommerce-shop-page/ | |
**/ | |
function skyverge_shop_display_post_meta() { | |
global $product; | |
// replace the custom field name with your own | |
$location = get_post_meta( $product->id, 'location', true ); | |
$points = get_post_meta( $product->id, 'points', true ); | |
// (optional) cleans up custom field names: replace underscores with spaces | |
$location = str_replace( '_', ' ', $location ); | |
// Add these fields to the shop loop if set | |
if ( ! empty( $location ) ) { | |
echo '<div class="product-meta"><span class="product-meta-title">Location:</span> ' . ucwords( $location ) . '</div>'; | |
} | |
if ( ! empty( $points ) ) { | |
echo '<div class="product-meta"><span class="product-meta-title">SkyPoints:</span> ' . $points . '</div>'; | |
} | |
} | |
add_action( 'woocommerce_after_shop_loop_item', 'skyverge_shop_display_post_meta', 9 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment