Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Created December 3, 2018 19:09
Show Gist options
  • Save EricBusch/c112c53db53b923f0c93a2bb69adde3f to your computer and use it in GitHub Desktop.
Save EricBusch/c112c53db53b923f0c93a2bb69adde3f to your computer and use it in GitHub Desktop.
Display Datafeedr Product Data in WooCommerce Loop
<?php
/**
* Display product fields before the product's title in the Loop.
*
* @global WC_Product $product
*/
function mycode_display_extra_data_in_loop() {
global $product;
$datafeedr_product = dfrps_product( $product->get_id() );
$datafeedr_product = is_string( $datafeedr_product ) ? [] : $datafeedr_product;
// var_dump( $datafeedr_product ); Uncomment this line to view all fields for this product.
if ( isset( $datafeedr_product['color'] ) ) {
echo '<div>Color: ' . $datafeedr_product['color'] . '</div>';
}
if ( isset( $datafeedr_product['material'] ) ) {
echo '<div>Material: ' . $datafeedr_product['material'] . '</div>';
}
if ( isset( $datafeedr_product['condition'] ) ) {
echo '<div>Condition: ' . $datafeedr_product['condition'] . '</div>';
}
}
add_action( 'woocommerce_before_shop_loop_item_title', 'mycode_display_extra_data_in_loop', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment