improved structured data - limits product structured data on archives and shop page

This commit is contained in:
opportus 2016-08-26 16:57:49 +02:00
parent 9001f094ff
commit fff204490c
1 changed files with 20 additions and 15 deletions

View File

@ -37,7 +37,7 @@ class WC_Structured_Data {
add_action( 'wp_footer', array( $this, 'output_structured_data' ), 10, 0 );
// Filters...
add_filter( 'woocommerce_structured_data_product_variable_offers', array( $this, 'disable_variable_product_offers' ), 10, 1 );
add_filter( 'woocommerce_structured_data_product_limit', array( $this, 'limit_product_data' ), 10, 1 );
}
/**
@ -187,13 +187,13 @@ class WC_Structured_Data {
}
/**
* Disables variable product offers for looped products.
* Limit Product structured data.
*
* @param bool $variable_offers
* @return bool $variable_offers
* @param bool $limit_data
* @return bool $limit_data
*/
public function disable_variable_product_offers( $variable_offers ) {
return $variable_offers = is_product_taxonomy() || is_shop() ? false : true;
public function limit_product_data( $limit_data ) {
return $limit_data = is_product_taxonomy() || is_shop() ? true : false;
}
/*
@ -219,11 +219,11 @@ class WC_Structured_Data {
*
* @uses `woocommerce_single_product_summary` action hook
* @uses `woocommerce_shop_loop` action hook
* @param bool|object $product (default: false)
* @param bool $variable_offers (default: true)
* @param bool|object $product (default: false)
* @param bool $limit_data (default: false)
* @return bool
*/
public function generate_product_data( $product = false, $variable_offers = true ) {
public function generate_product_data( $product = false, $limit_data = false ) {
if ( $product === false ) {
global $product;
}
@ -232,9 +232,18 @@ class WC_Structured_Data {
return false;
}
$variable_offers = apply_filters( 'woocommerce_structured_data_product_variable_offers', $variable_offers );
$limit_data = apply_filters( 'woocommerce_structured_data_product_limit', $limit_data );
$markup['@type'] = 'Product';
$markup['@id'] = get_permalink( $product->get_id() );
$markup['url'] = $markup['@id'];
$markup['name'] = $product->get_title();
if ( $variable_offers && $is_variable = $product->is_type( 'variable' ) ) {
if ( $limit_data ) {
return $this->set_data( apply_filters( 'woocommerce_structured_data_product', $markup, $product ) );
}
if ( $is_variable = $product->is_type( 'variable' ) ) {
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
@ -261,10 +270,6 @@ class WC_Structured_Data {
);
}
$markup['@type'] = 'Product';
$markup['@id'] = get_permalink( $product->get_id() );
$markup['url'] = get_permalink( $product->get_id() );
$markup['name'] = $product->get_title();
$markup['description'] = get_the_excerpt( $product->get_id() );
$markup['offers'] = $markup_offers;