2016-07-17 02:42:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Structured data's handler and generator using JSON-LD format.
|
|
|
|
*
|
2016-07-24 21:46:30 +00:00
|
|
|
* @class WC_Structured_Data
|
2016-08-11 12:58:05 +00:00
|
|
|
* @since 2.7.0
|
2016-07-24 21:46:30 +00:00
|
|
|
* @version 2.7.0
|
|
|
|
* @package WooCommerce/Classes
|
2016-08-11 12:58:05 +00:00
|
|
|
* @author Clement Cazaud <opportus@gmail.com>
|
2016-07-17 02:42:46 +00:00
|
|
|
*/
|
2016-07-19 19:36:52 +00:00
|
|
|
class WC_Structured_Data {
|
2016-08-11 09:17:14 +00:00
|
|
|
|
|
|
|
/**
|
2016-08-11 12:58:05 +00:00
|
|
|
* @var null|array $_data Partially structured data from `generate_*` methods
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
|
|
|
private $_data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
2016-08-11 10:04:12 +00:00
|
|
|
*/
|
2016-08-11 09:17:14 +00:00
|
|
|
public function __construct() {
|
|
|
|
// Generate data...
|
2016-08-12 13:19:26 +00:00
|
|
|
add_action( 'woocommerce_before_main_content', array( $this, 'generate_website_data' ), 30, 0 );
|
|
|
|
add_action( 'woocommerce_breadcrumb', array( $this, 'generate_breadcrumb_data' ), 10, 1 );
|
|
|
|
add_action( 'woocommerce_shop_loop', array( $this, 'generate_product_data' ), 10, 0 );
|
|
|
|
add_action( 'woocommerce_single_product_summary', array( $this, 'generate_product_data' ), 60, 0 );
|
2016-08-11 12:58:05 +00:00
|
|
|
add_action( 'woocommerce_review_meta', array( $this, 'generate_product_review_data' ), 20, 1 );
|
2016-08-12 13:19:26 +00:00
|
|
|
add_action( 'woocommerce_email_order_details', array( $this, 'generate_email_order_data' ), 20, 3 );
|
2016-08-11 09:17:14 +00:00
|
|
|
// Enqueue structured data...
|
2016-08-12 13:19:26 +00:00
|
|
|
add_action( 'woocommerce_email_order_details', array( $this, 'enqueue_data' ), 30, 0 );
|
|
|
|
add_action( 'wp_footer', array( $this, 'enqueue_data_type_for_page' ), 10, 0 );
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-11 12:58:05 +00:00
|
|
|
* Sets `$this->_data`.
|
2016-08-10 22:23:26 +00:00
|
|
|
*
|
2016-08-12 00:55:52 +00:00
|
|
|
* @param array $data
|
2016-08-12 20:58:23 +00:00
|
|
|
* @param bool $reset (default: false)
|
2016-08-11 12:58:05 +00:00
|
|
|
* @return bool
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
2016-08-12 00:55:52 +00:00
|
|
|
public function set_data( $data, $reset = false ) {
|
2016-08-11 23:29:35 +00:00
|
|
|
if ( ! is_array( $data ) || ! array_key_exists( '@type', $data ) ) {
|
2016-08-11 09:17:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-12 00:55:52 +00:00
|
|
|
if ( $reset && isset( $this->_data ) ) {
|
2016-08-11 09:17:14 +00:00
|
|
|
unset( $this->_data );
|
|
|
|
}
|
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
$this->_data[] = $data;
|
2016-08-11 09:17:14 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets `$this->_data`.
|
|
|
|
*
|
2016-08-11 12:58:05 +00:00
|
|
|
* @return array $data
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
|
|
|
public function get_data() {
|
2016-08-11 23:29:35 +00:00
|
|
|
return $data = isset( $this->_data ) ? $this->_data : array();
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-12 20:58:23 +00:00
|
|
|
* Returns structured data.
|
2016-08-11 09:17:14 +00:00
|
|
|
*
|
2016-08-12 20:58:23 +00:00
|
|
|
* List of types available by default for specific request
|
|
|
|
* 'Product',
|
|
|
|
* 'Review',
|
|
|
|
* 'BreadcrumbList',
|
|
|
|
* 'WebSite',
|
|
|
|
* 'Order',
|
|
|
|
*
|
|
|
|
* @param bool|array $requested_types (default: false)
|
|
|
|
* @return array
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
2016-08-12 20:58:23 +00:00
|
|
|
public function get_structured_data( $requested_types = false ) {
|
|
|
|
if ( empty( $this->get_data() ) || ( $requested_types && ! is_array( $requested_types ) ) ) {
|
|
|
|
return array();
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 13:19:26 +00:00
|
|
|
foreach ( $this->get_data() as $value ) {
|
2016-08-12 20:58:23 +00:00
|
|
|
$data[ $value['@type'] ][] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $data as $type => $value ) {
|
|
|
|
$data[ $type ] = count( $value ) > 1 ? array( '@graph' => $value ) : $value[0];
|
|
|
|
$data[ $type ] = apply_filters( 'woocommerce_structured_data_context', array( '@context' => 'http://schema.org/' ), $data, $type, $value ) + $data[ $type ];
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 20:58:23 +00:00
|
|
|
foreach ( $data as $type => $value ) {
|
|
|
|
if ( $requested_types ) {
|
|
|
|
foreach ( $requested_types as $requested_type ) {
|
|
|
|
if ( $requested_type === $type ) {
|
|
|
|
$structured_data[] = $value;
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 09:17:14 +00:00
|
|
|
} else {
|
2016-08-12 20:58:23 +00:00
|
|
|
$structured_data[] = $value;
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
2016-08-12 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! isset( $structured_data ) ) {
|
|
|
|
return array();
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 20:58:23 +00:00
|
|
|
$structured_data = count( $structured_data ) > 1 ? array( '@graph' => $structured_data ) : $structured_data[0];
|
2016-08-11 23:29:35 +00:00
|
|
|
|
2016-08-12 20:58:23 +00:00
|
|
|
return $structured_data;
|
2016-08-11 23:29:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sanitizes, encodes and echoes structured data.
|
|
|
|
*
|
2016-08-12 00:55:52 +00:00
|
|
|
* @uses `woocommerce_email_order_details` action hook
|
2016-08-11 12:58:05 +00:00
|
|
|
* @param bool|array $requested_types (default: false)
|
2016-08-11 23:29:35 +00:00
|
|
|
* @return bool
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
2016-08-11 23:29:35 +00:00
|
|
|
public function enqueue_data( $requested_types = false ) {
|
2016-08-12 20:58:23 +00:00
|
|
|
if ( $structured_data = $this->sanitize_data( $this->get_structured_data( $requested_types ) ) ) {
|
|
|
|
echo '<script type="application/ld+json">' . wp_json_encode( $structured_data ) . '</script>';
|
2016-08-11 23:29:35 +00:00
|
|
|
|
2016-08-12 00:55:52 +00:00
|
|
|
return true;
|
2016-08-12 20:58:23 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-12 00:55:52 +00:00
|
|
|
* Sanitizes, encodes and echoes specific structured data type on scpecific page.
|
2016-08-11 12:58:05 +00:00
|
|
|
*
|
2016-08-11 23:29:35 +00:00
|
|
|
* @uses `wp_footer` action hook
|
|
|
|
* @return bool
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
2016-08-12 09:01:02 +00:00
|
|
|
public function enqueue_data_type_for_page() {
|
|
|
|
$requested_types = apply_filters( 'woocommerce_structured_data_type_for_page', array(
|
2016-08-11 23:29:35 +00:00
|
|
|
is_shop() && is_front_page() ? 'WebSite' : null,
|
|
|
|
'BreadcrumbList',
|
|
|
|
'Product',
|
|
|
|
'Review',
|
|
|
|
) );
|
|
|
|
|
2016-08-12 00:55:52 +00:00
|
|
|
return $this->enqueue_data( $requested_types );
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-11 12:58:05 +00:00
|
|
|
* Sanitizes data.
|
2016-08-11 09:17:14 +00:00
|
|
|
*
|
|
|
|
* @param array $data
|
2016-08-11 12:58:05 +00:00
|
|
|
* @return array
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
|
|
|
public function sanitize_data( $data ) {
|
|
|
|
if ( ! $data ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $data as $key => $value ) {
|
|
|
|
$sanitized_data[ sanitize_text_field( $key ) ] = is_array( $value ) ? $this->sanitize_data( $value ) : sanitize_text_field( $value );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sanitized_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-11 23:29:35 +00:00
|
|
|
* Generates Product structured data.
|
2016-08-11 12:58:05 +00:00
|
|
|
*
|
2016-08-11 23:29:35 +00:00
|
|
|
* @uses `woocommerce_single_product_summary` action hook
|
2016-08-12 00:55:52 +00:00
|
|
|
* @uses `woocommerce_shop_loop` action hook
|
2016-08-11 23:29:35 +00:00
|
|
|
* @param bool|object $product (default: false)
|
|
|
|
* @return bool
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
2016-08-11 23:29:35 +00:00
|
|
|
public function generate_product_data( $product = false ) {
|
|
|
|
if ( ! $product ) {
|
|
|
|
global $product;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! is_object( $product ) ) {
|
|
|
|
return false;
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $is_multi_variation = count( $product->get_children() ) > 1 ? true : false ) {
|
|
|
|
$variations = $product->get_available_variations();
|
|
|
|
} else {
|
|
|
|
$variations = array( null );
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $variations as $variation ) {
|
|
|
|
$product_variation = $is_multi_variation ? wc_get_product( $variation['variation_id'] ) : $product;
|
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup_offers[] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'Offer',
|
|
|
|
'priceCurrency' => get_woocommerce_currency(),
|
|
|
|
'price' => $product_variation->get_price(),
|
|
|
|
'availability' => 'http://schema.org/' . $stock = ( $product_variation->is_in_stock() ? 'InStock' : 'OutOfStock' ),
|
|
|
|
'sku' => $product_variation->get_sku(),
|
|
|
|
'image' => wp_get_attachment_url( $product_variation->get_image_id() ),
|
|
|
|
'description' => $is_multi_variation ? $product_variation->get_variation_description() : '',
|
|
|
|
'seller' => array(
|
|
|
|
'@type' => 'Organization',
|
|
|
|
'name' => get_bloginfo( 'name' ),
|
|
|
|
'url' => get_bloginfo( 'url' ),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-08-12 16:13:11 +00:00
|
|
|
$markup['@type'] = 'Product';
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['@id'] = get_the_permalink();
|
|
|
|
$markup['name'] = get_the_title();
|
|
|
|
$markup['description'] = get_the_excerpt();
|
|
|
|
$markup['url'] = get_the_permalink();
|
|
|
|
$markup['offers'] = $markup_offers;
|
2016-08-11 09:17:14 +00:00
|
|
|
|
|
|
|
if ( $product->get_rating_count() ) {
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['aggregateRating'] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'AggregateRating',
|
|
|
|
'ratingValue' => $product->get_average_rating(),
|
|
|
|
'ratingCount' => $product->get_rating_count(),
|
|
|
|
'reviewCount' => $product->get_review_count(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
return $this->set_data( apply_filters( 'woocommerce_structured_data_product', $markup, $product ) );
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-11 23:29:35 +00:00
|
|
|
* Generates Product Review structured data.
|
2016-08-11 09:17:14 +00:00
|
|
|
*
|
2016-08-11 23:29:35 +00:00
|
|
|
* @uses `woocommerce_review_meta` action hook
|
2016-08-12 00:55:52 +00:00
|
|
|
* @param object $comment
|
2016-08-11 23:29:35 +00:00
|
|
|
* @return bool
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
|
|
|
public function generate_product_review_data( $comment ) {
|
2016-08-12 00:55:52 +00:00
|
|
|
if ( ! is_object( $comment ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['@type'] = 'Review';
|
|
|
|
$markup['@id'] = get_the_permalink() . '#li-comment-' . get_comment_ID();
|
|
|
|
$markup['datePublished'] = get_comment_date( 'c' );
|
|
|
|
$markup['description'] = get_comment_text();
|
|
|
|
$markup['itemReviewed'] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'Product',
|
|
|
|
'name' => get_the_title(),
|
|
|
|
);
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['reviewRating'] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'rating',
|
|
|
|
'ratingValue' => intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ),
|
|
|
|
);
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['author'] = array(
|
2016-08-11 10:04:12 +00:00
|
|
|
'@type' => 'Person',
|
|
|
|
'name' => get_comment_author(),
|
2016-08-11 09:17:14 +00:00
|
|
|
);
|
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
return $this->set_data( apply_filters( 'woocommerce_structured_data_product_review', $markup, $comment ) );
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-11 23:29:35 +00:00
|
|
|
* Generates BreadcrumbList structured data.
|
2016-08-11 09:17:14 +00:00
|
|
|
*
|
2016-08-11 23:29:35 +00:00
|
|
|
* @uses `woocommerce_breadcrumb` action hook
|
2016-08-12 00:55:52 +00:00
|
|
|
* @param array $breadcrumb
|
|
|
|
* @return bool|void
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
2016-08-12 00:55:52 +00:00
|
|
|
public function generate_breadcrumb_data( $breadcrumb ) {
|
|
|
|
if ( ! is_array( $breadcrumb ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty( $breadcrumb = $breadcrumb['breadcrumb'] ) ) {
|
2016-08-11 09:17:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-12 00:55:52 +00:00
|
|
|
$position = 1;
|
2016-08-11 09:17:14 +00:00
|
|
|
|
|
|
|
foreach ( $breadcrumb as $key => $value ) {
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup_crumbs[] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'ListItem',
|
|
|
|
'position' => $position ++,
|
2016-08-12 00:55:52 +00:00
|
|
|
'item' => array(
|
|
|
|
'@id' => ! empty( $value[1] ) && sizeof( $breadcrumb ) !== $key + 1 ? $value[1] : '#',
|
|
|
|
'name' => $value[0],
|
|
|
|
),
|
2016-08-11 09:17:14 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['@type'] = 'BreadcrumbList';
|
|
|
|
$markup['itemListElement'] = $markup_crumbs;
|
2016-08-11 09:17:14 +00:00
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
return $this->set_data( apply_filters( 'woocommerce_structured_data_breadcrumb', $markup, $breadcrumb ) );
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-11 23:29:35 +00:00
|
|
|
* Generates WebSite structured data.
|
2016-08-11 12:58:05 +00:00
|
|
|
*
|
2016-08-11 23:29:35 +00:00
|
|
|
* @uses `woocommerce_before_main_content` action hook
|
|
|
|
* @return bool
|
2016-08-11 09:17:14 +00:00
|
|
|
*/
|
2016-08-11 23:29:35 +00:00
|
|
|
public function generate_website_data() {
|
|
|
|
$markup['@type'] = 'WebSite';
|
|
|
|
$markup['name'] = get_bloginfo( 'name' );
|
|
|
|
$markup['url'] = get_bloginfo( 'url' );
|
|
|
|
$markup['potentialAction'] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'SearchAction',
|
|
|
|
'target' => get_bloginfo( 'url' ) . '/?s={search_term_string}&post_type=product',
|
|
|
|
'query-input' => 'required name=search_term_string',
|
|
|
|
);
|
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
return $this->set_data( apply_filters( 'woocommerce_structured_data_website', $markup ) );
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-11 23:29:35 +00:00
|
|
|
* Generates Email Order structured data.
|
2016-08-11 12:58:05 +00:00
|
|
|
*
|
2016-08-11 23:29:35 +00:00
|
|
|
* @uses `woocommerce_email_order_details` action hook
|
2016-08-12 20:58:23 +00:00
|
|
|
* @param object $order
|
|
|
|
* @param bool $sent_to_admin (default: false)
|
|
|
|
* @param bool $plain_text (default: false)
|
2016-08-12 00:55:52 +00:00
|
|
|
* @return bool|void
|
2016-08-10 22:23:26 +00:00
|
|
|
*/
|
|
|
|
public function generate_email_order_data( $order, $sent_to_admin = false, $plain_text = false ) {
|
2016-08-12 00:55:52 +00:00
|
|
|
if ( ! is_object( $order ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-10 22:23:26 +00:00
|
|
|
if ( $plain_text ) {
|
|
|
|
return;
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
2016-08-10 22:23:26 +00:00
|
|
|
|
|
|
|
foreach ( $order->get_items() as $item ) {
|
|
|
|
if ( ! apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
|
|
|
|
continue;
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
2016-08-10 22:23:26 +00:00
|
|
|
|
|
|
|
$product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
|
|
|
|
$product_exists = is_object( $product );
|
|
|
|
$is_visible = $product_exists && $product->is_visible();
|
2016-08-11 09:17:14 +00:00
|
|
|
$order_url = $sent_to_admin ? admin_url( 'post.php?post=' . absint( $order->id ) . '&action=edit' ) : $order->get_view_order_url();
|
2016-08-10 22:23:26 +00:00
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup_offers[] = array(
|
2016-08-10 22:23:26 +00:00
|
|
|
'@type' => 'Offer',
|
|
|
|
'price' => $order->get_line_subtotal( $item ),
|
2016-08-11 09:17:14 +00:00
|
|
|
'priceCurrency' => $order->get_currency(),
|
|
|
|
'priceSpecification' => array(
|
2016-08-11 10:04:12 +00:00
|
|
|
'price' => $order->get_line_subtotal( $item ),
|
|
|
|
'priceCurrency' => $order->get_currency(),
|
|
|
|
'eligibleQuantity' => array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'QuantitativeValue',
|
|
|
|
'value' => apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'itemOffered' => array(
|
|
|
|
'@type' => 'Product',
|
|
|
|
'name' => apply_filters( 'woocommerce_order_item_name', $item['name'], $item, $is_visible ),
|
|
|
|
'sku' => $product_exists ? $product->get_sku() : '',
|
|
|
|
'image' => $product_exists ? wp_get_attachment_image_url( $product->get_image_id() ) : '',
|
|
|
|
'url' => $is_visible ? get_permalink( $product->get_id() ) : get_home_url(),
|
|
|
|
),
|
|
|
|
'seller' => array(
|
|
|
|
'@type' => 'Organization',
|
|
|
|
'name' => get_bloginfo( 'name' ),
|
|
|
|
'url' => get_bloginfo( 'url' ),
|
|
|
|
),
|
2016-08-10 22:23:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( $order->get_status() ) {
|
|
|
|
case 'pending':
|
|
|
|
$order_status = 'http://schema.org/OrderPaymentDue';
|
|
|
|
break;
|
|
|
|
case 'processing':
|
|
|
|
$order_status = 'http://schema.org/OrderProcessing';
|
|
|
|
break;
|
|
|
|
case 'on-hold':
|
|
|
|
$order_status = 'http://schema.org/OrderProblem';
|
|
|
|
break;
|
|
|
|
case 'completed':
|
|
|
|
$order_status = 'http://schema.org/OrderDelivered';
|
|
|
|
break;
|
|
|
|
case 'cancelled':
|
|
|
|
$order_status = 'http://schema.org/OrderCancelled';
|
|
|
|
break;
|
|
|
|
case 'refunded':
|
|
|
|
$order_status = 'http://schema.org/OrderReturned';
|
|
|
|
break;
|
|
|
|
case 'failed':
|
|
|
|
$order_status = 'http://schema.org/OrderProblem';
|
|
|
|
break;
|
2016-08-11 09:17:14 +00:00
|
|
|
}
|
2016-08-10 22:23:26 +00:00
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['@type'] = 'Order';
|
|
|
|
$markup['orderStatus'] = $order_status;
|
|
|
|
$markup['orderNumber'] = $order->get_order_number();
|
|
|
|
$markup['orderDate'] = date( 'c', $order->get_date_created() );
|
|
|
|
$markup['url'] = $order_url;
|
|
|
|
$markup['acceptedOffer'] = $markup_offers;
|
|
|
|
$markup['discount'] = $order->get_total_discount();
|
|
|
|
$markup['discountCurrency'] = $order->get_currency();
|
|
|
|
$markup['price'] = $order->get_total();
|
|
|
|
$markup['priceCurrency'] = $order->get_currency();
|
|
|
|
$markup['priceSpecification'] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'price' => $order->get_total(),
|
|
|
|
'priceCurrency' => $order->get_currency(),
|
|
|
|
'valueAddedTaxIncluded' => true,
|
|
|
|
);
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['billingAddress'] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'PostalAddress',
|
|
|
|
'name' => $order->get_formatted_billing_full_name(),
|
|
|
|
'streetAddress' => $order->get_billing_address_1(),
|
|
|
|
'postalCode' => $order->get_billing_postcode(),
|
|
|
|
'addressLocality' => $order->get_billing_city(),
|
|
|
|
'addressRegion' => $order->get_billing_state(),
|
|
|
|
'addressCountry' => $order->get_billing_country(),
|
|
|
|
'email' => $order->get_billing_email(),
|
|
|
|
'telephone' => $order->get_billing_phone(),
|
|
|
|
);
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['customer'] = array(
|
2016-08-11 09:17:14 +00:00
|
|
|
'@type' => 'Person',
|
|
|
|
'name' => $order->get_formatted_billing_full_name(),
|
|
|
|
);
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['merchant'] = array(
|
2016-08-10 22:23:26 +00:00
|
|
|
'@type' => 'Organization',
|
2016-08-11 09:17:14 +00:00
|
|
|
'name' => get_bloginfo( 'name' ),
|
|
|
|
'url' => get_bloginfo( 'url' ),
|
2016-08-10 22:23:26 +00:00
|
|
|
);
|
2016-08-11 23:29:35 +00:00
|
|
|
$markup['potentialAction'] = array(
|
2016-08-10 22:23:26 +00:00
|
|
|
'@type' => 'ViewAction',
|
2016-08-11 09:17:14 +00:00
|
|
|
'name' => 'View Order',
|
|
|
|
'url' => $order_url,
|
2016-08-10 22:23:26 +00:00
|
|
|
'target' => $order_url,
|
|
|
|
);
|
|
|
|
|
2016-08-11 23:29:35 +00:00
|
|
|
return $this->set_data( apply_filters( 'woocommerce_structured_data_email_order', $markup, $sent_to_admin, $order ), true );
|
2016-08-10 22:23:26 +00:00
|
|
|
}
|
2016-07-17 02:42:46 +00:00
|
|
|
}
|