improved structured data - some final little tweaks
This commit is contained in:
parent
5535da6a5b
commit
6c1990c3cf
|
@ -72,7 +72,8 @@ class WC_Structured_Data {
|
||||||
/**
|
/**
|
||||||
* Structures and returns data.
|
* Structures and returns data.
|
||||||
*
|
*
|
||||||
* List of types available by default for specific request
|
* List of types available by default for specific request:
|
||||||
|
*
|
||||||
* 'product',
|
* 'product',
|
||||||
* 'review',
|
* 'review',
|
||||||
* 'breadcrumblist',
|
* 'breadcrumblist',
|
||||||
|
@ -135,9 +136,9 @@ class WC_Structured_Data {
|
||||||
public function output_structured_data( $requested_types = true ) {
|
public function output_structured_data( $requested_types = true ) {
|
||||||
if ( $requested_types === true ) {
|
if ( $requested_types === true ) {
|
||||||
$requested_types = apply_filters( 'woocommerce_structured_data_type_for_page', array(
|
$requested_types = apply_filters( 'woocommerce_structured_data_type_for_page', array(
|
||||||
is_shop() || is_product_category() || is_product() ? 'product' : null,
|
is_shop() || is_product_category() || is_product() ? 'product' : null,
|
||||||
is_shop() && is_front_page() ? 'website' : null,
|
is_shop() && is_front_page() ? 'website' : null,
|
||||||
is_product() ? 'review' : null,
|
is_product() ? 'review' : null,
|
||||||
! is_shop() ? 'breadcrumblist' : null,
|
! is_shop() ? 'breadcrumblist' : null,
|
||||||
'order',
|
'order',
|
||||||
) );
|
) );
|
||||||
|
@ -152,30 +153,6 @@ class WC_Structured_Data {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates, sanitizes, encodes and outputs specific structured data type.
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param mixed $object
|
|
||||||
* @param mixed $param_1 (default: null)
|
|
||||||
* @param mixed $param_2 (default: null)
|
|
||||||
* @param mixed $param_3 (default: null)
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function generate_output_structured_data( $type, $object, $param_1 = null, $param_2 = null, $param_3 = null ) {
|
|
||||||
if ( ! is_string( $type ) || ! $object ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$generate = 'generate_' . $type . '_data';
|
|
||||||
|
|
||||||
if ( $this->$generate( $object, $param_1, $param_2, $param_3 ) ) {
|
|
||||||
return $this->output_structured_data( $type );
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitizes data.
|
* Sanitizes data.
|
||||||
*
|
*
|
||||||
|
@ -194,6 +171,48 @@ class WC_Structured_Data {
|
||||||
return $sanitized_data;
|
return $sanitized_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates, sanitizes, encodes and outputs specific structured data type.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param mixed $object (default: null)
|
||||||
|
* @param mixed $param_1 (default: null)
|
||||||
|
* @param mixed $param_2 (default: null)
|
||||||
|
* @param mixed $param_3 (default: null)
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function generate_output_structured_data( $type, $object = null, $param_1 = null, $param_2 = null, $param_3 = null ) {
|
||||||
|
if ( ! is_string( $type ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$generate = 'generate_' . $type . '_data';
|
||||||
|
|
||||||
|
if ( $this->$generate( $object, $param_1, $param_2, $param_3 ) ) {
|
||||||
|
return $this->output_structured_data( $type );
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Generators
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Methods for generating specific structured data types:
|
||||||
|
|
|
||||||
|
| - Product
|
||||||
|
| - Review
|
||||||
|
| - BreadcrumbList
|
||||||
|
| - WebSite
|
||||||
|
| - Order
|
||||||
|
|
|
||||||
|
| The generated data is stored into `$this->_data`.
|
||||||
|
| See the methods above for handling `$this->_data`.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates Product structured data.
|
* Generates Product structured data.
|
||||||
*
|
*
|
||||||
|
@ -211,14 +230,10 @@ class WC_Structured_Data {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $is_multi_variation = count( $product->get_children() ) > 1 ? true : false ) {
|
$variations = count( $product->get_children() ) > 1 ? $product->get_available_variations() : array( $product );
|
||||||
$variations = $product->get_available_variations();
|
|
||||||
} else {
|
|
||||||
$variations = array( null );
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( $variations as $variation ) {
|
foreach ( $variations as $variation ) {
|
||||||
$product_variation = $is_multi_variation ? wc_get_product( $variation['variation_id'] ) : $product;
|
$product_variation = count( $variations ) > 1 ? wc_get_product( $variation['variation_id'] ) : $variation;
|
||||||
|
|
||||||
$markup_offers[] = array(
|
$markup_offers[] = array(
|
||||||
'@type' => 'Offer',
|
'@type' => 'Offer',
|
||||||
|
@ -227,7 +242,7 @@ class WC_Structured_Data {
|
||||||
'availability' => 'http://schema.org/' . $stock = ( $product_variation->is_in_stock() ? 'InStock' : 'OutOfStock' ),
|
'availability' => 'http://schema.org/' . $stock = ( $product_variation->is_in_stock() ? 'InStock' : 'OutOfStock' ),
|
||||||
'sku' => $product_variation->get_sku(),
|
'sku' => $product_variation->get_sku(),
|
||||||
'image' => wp_get_attachment_url( $product_variation->get_image_id() ),
|
'image' => wp_get_attachment_url( $product_variation->get_image_id() ),
|
||||||
'description' => $is_multi_variation ? $product_variation->get_variation_description() : '',
|
'description' => count( $variations ) > 1 ? $product_variation->get_variation_description() : '',
|
||||||
'seller' => array(
|
'seller' => array(
|
||||||
'@type' => 'Organization',
|
'@type' => 'Organization',
|
||||||
'name' => get_bloginfo( 'name' ),
|
'name' => get_bloginfo( 'name' ),
|
||||||
|
|
|
@ -510,7 +510,7 @@ global $wc_map_deprecated_filters;
|
||||||
$wc_map_deprecated_filters = array(
|
$wc_map_deprecated_filters = array(
|
||||||
'woocommerce_add_to_cart_fragments' => 'add_to_cart_fragments',
|
'woocommerce_add_to_cart_fragments' => 'add_to_cart_fragments',
|
||||||
'woocommerce_add_to_cart_redirect' => 'add_to_cart_redirect',
|
'woocommerce_add_to_cart_redirect' => 'add_to_cart_redirect',
|
||||||
'woocommerce_structured_data_order' => 'woocommerce_email_order_schema_markup'
|
'woocommerce_structured_data_order' => 'woocommerce_email_order_schema_markup',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $wc_map_deprecated_filters as $new => $old ) {
|
foreach ( $wc_map_deprecated_filters as $new => $old ) {
|
||||||
|
|
Loading…
Reference in New Issue