Created
December 3, 2018 19:12
-
-
Save EricBusch/a3ec79f8fef65076476afbe2d5fae24f to your computer and use it in GitHub Desktop.
Display Datafeedr Product data on single product page in WooCommerce.
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 "buy" button on single product page. | |
* | |
* @global WC_Product $product | |
*/ | |
function mycode_display_extra_data_on_single_product_page() { | |
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_add_to_cart_button', 'mycode_display_extra_data_on_single_product_page', 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment