WordPress at Your Fingertips
function is not described

WC_Structured_Data::generate_order_data() public WC 1.0

Generates Order structured data.

Hooked into woocommerce_email_order_details hook.

{} It's a method of the class: WC_Structured_Data{}

Return

null. Nothing.

Usage

$WC_Structured_Data = new WC_Structured_Data();
$WC_Structured_Data->generate_order_data( $order, $sent_to_admin, $plain_text );
$order(WP_Order) (required)
Order data.
$sent_to_admin(true|false)
Send to admin (default: false).
Default: false
$plain_text(true|false)
Plain text email (default: false).
Default: false

Code of WC_Structured_Data::generate_order_data() WC 5.6.0

public function generate_order_data( $order, $sent_to_admin = false, $plain_text = false ) {
	if ( $plain_text || ! is_a( $order, 'WC_Order' ) ) {
		return;
	}

	$shop_name      = get_bloginfo( 'name' );
	$shop_url       = home_url();
	$order_url      = $sent_to_admin ? $order->get_edit_order_url() : $order->get_view_order_url();
	$order_statuses = array(
		'pending'    => 'https://schema.org/OrderPaymentDue',
		'processing' => 'https://schema.org/OrderProcessing',
		'on-hold'    => 'https://schema.org/OrderProblem',
		'completed'  => 'https://schema.org/OrderDelivered',
		'cancelled'  => 'https://schema.org/OrderCancelled',
		'refunded'   => 'https://schema.org/OrderReturned',
		'failed'     => 'https://schema.org/OrderProblem',
	);

	$markup_offers = array();
	foreach ( $order->get_items() as $item ) {
		if ( ! apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
			continue;
		}

		$product        = $item->get_product();
		$product_exists = is_object( $product );
		$is_visible     = $product_exists && $product->is_visible();

		$markup_offers[] = array(
			'@type'              => 'Offer',
			'price'              => $order->get_line_subtotal( $item ),
			'priceCurrency'      => $order->get_currency(),
			'priceSpecification' => array(
				'price'            => $order->get_line_subtotal( $item ),
				'priceCurrency'    => $order->get_currency(),
				'eligibleQuantity' => array(
					'@type' => 'QuantitativeValue',
					'value' => apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item ),
				),
			),
			'itemOffered'        => array(
				'@type' => 'Product',
				'name'  => wp_kses_post( apply_filters( 'woocommerce_order_item_name', $item->get_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'  => $shop_name,
				'url'   => $shop_url,
			),
		);
	}

	$markup                       = array();
	$markup['@type']              = 'Order';
	$markup['url']                = $order_url;
	$markup['orderStatus']        = isset( $order_statuses[ $order->get_status() ] ) ? $order_statuses[ $order->get_status() ] : '';
	$markup['orderNumber']        = $order->get_order_number();
	$markup['orderDate']          = $order->get_date_created()->format( 'c' );
	$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(
		'price'                 => $order->get_total(),
		'priceCurrency'         => $order->get_currency(),
		'valueAddedTaxIncluded' => 'true',
	);
	$markup['billingAddress']     = array(
		'@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(),
	);
	$markup['customer']           = array(
		'@type' => 'Person',
		'name'  => $order->get_formatted_billing_full_name(),
	);
	$markup['merchant']           = array(
		'@type' => 'Organization',
		'name'  => $shop_name,
		'url'   => $shop_url,
	);
	$markup['potentialAction']    = array(
		'@type'  => 'ViewAction',
		'name'   => 'View Order',
		'url'    => $order_url,
		'target' => $order_url,
	);

	$this->set_data( apply_filters( 'woocommerce_structured_data_order', $markup, $sent_to_admin, $order ), true );
}