Created
December 3, 2018 19:09
-
-
Save EricBusch/c112c53db53b923f0c93a2bb69adde3f to your computer and use it in GitHub Desktop.
Display Datafeedr Product Data in WooCommerce Loop
This file contains 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
<?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