Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Created December 3, 2018 19:12
Show Gist options
  • Save EricBusch/a3ec79f8fef65076476afbe2d5fae24f to your computer and use it in GitHub Desktop.
Save EricBusch/a3ec79f8fef65076476afbe2d5fae24f to your computer and use it in GitHub Desktop.
Display Datafeedr Product data on single product page in WooCommerce.
<?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