Skip to content

Commit

Permalink
Added Support for WooCommerce Product Structured Data.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Dec 20, 2018
1 parent 6a2b5c5 commit a5d9767
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion includes/class-featured-image-by-url-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct() {

add_action( 'init', array( $this, 'knawatfibu_set_thumbnail_id_true' ) );
add_filter( 'post_thumbnail_html', array( $this, 'knawatfibu_overwrite_thumbnail_with_url' ), 999, 5 );
add_filter( 'woocommerce_structured_data_product', array( $this, 'knawatfibu_woo_structured_data_product_support' ), 99, 2 );

if( !is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
add_filter( 'wp_get_attachment_image_src', array( $this, 'knawatfibu_replace_attachment_image_src' ), 10, 4 );
Expand Down Expand Up @@ -443,4 +444,26 @@ public function knawatfibu_woo_thumb_support() {
}
}
}
}

/**
* Add Support for WooCommerce Product Structured Data.
*
* @since 1.0
* @param array $markup
* @param object $product
* @return array $markup
*/
function knawatfibu_woo_structured_data_product_support( $markup, $product ) {
if ( isset($markup['image']) && empty($markup['image']) ) {
global $knawatfibu;
$product_id = $product->get_id();
if( !$this->knawatfibu_is_disallow_posttype( 'product' ) && $product_id > 0 ){
$image_data = $knawatfibu->admin->knawatfibu_get_image_meta( $product_id );
if( !empty($image_data) && isset($image_data['img_url']) && !empty($image_data['img_url']) ) {
$markup['image'] = $image_data['img_url'];
}
}
}
return $markup;
}
}

0 comments on commit a5d9767

Please sign in to comment.