Merge branch 'master' into update/14848
# Conflicts: # includes/class-wc-structured-data.php
This commit is contained in:
commit
e0583d2cd9
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -388,6 +388,10 @@ table.variations {
|
|||
cursor: pointer;
|
||||
}
|
||||
|
||||
li:nth-child(4n+1) {
|
||||
clear: left;
|
||||
}
|
||||
|
||||
img {
|
||||
opacity: .5;
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -245,6 +245,10 @@ p.demo_store,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
li:nth-child(4n+1) {
|
||||
clear: left;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -853,7 +853,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
if ( $item_id = $item->get_id() ) {
|
||||
$this->items[ $items_key ][ $item_id ] = $item;
|
||||
} else {
|
||||
$this->items[ $items_key ][ 'new:' . sizeof( $this->items[ $items_key ] ) ] = $item;
|
||||
$this->items[ $items_key ][ 'new:' . $items_key . sizeof( $this->items[ $items_key ] ) ] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -939,10 +939,15 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
$line_item->set_variation( $item['variations'] );
|
||||
}
|
||||
|
||||
$item_id = $line_item->save();
|
||||
// Save or add to order.
|
||||
if ( $creating ) {
|
||||
$order->add_item( $line_item );
|
||||
} else {
|
||||
$item_id = $line_item->save();
|
||||
|
||||
if ( ! $item_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_line_item', __( 'Cannot create line item, try again.', 'woocommerce' ), 500 );
|
||||
if ( ! $item_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_line_item', __( 'Cannot create line item, try again.', 'woocommerce' ), 500 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1023,11 +1028,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
$item = new WC_Order_Item_Shipping();
|
||||
$item->set_order_id( $order->get_id() );
|
||||
$item->set_shipping_rate( $rate );
|
||||
$shipping_id = $item->save();
|
||||
|
||||
if ( ! $shipping_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_shipping', __( 'Cannot create shipping method, try again.', 'woocommerce' ), 500 );
|
||||
}
|
||||
$order->add_item( $item );
|
||||
} else {
|
||||
|
||||
$item = new WC_Order_Item_Shipping( $shipping['id'] );
|
||||
|
@ -1094,11 +1095,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
}
|
||||
}
|
||||
|
||||
$fee_id = $item->save();
|
||||
|
||||
if ( ! $fee_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_fee', __( 'Cannot create fee, try again.', 'woocommerce' ), 500 );
|
||||
}
|
||||
$order->add_item( $item );
|
||||
} else {
|
||||
|
||||
$item = new WC_Order_Item_Fee( $fee['id'] );
|
||||
|
@ -1157,11 +1154,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
'discount_tax' => 0,
|
||||
'order_id' => $order->get_id(),
|
||||
) );
|
||||
$coupon_id = $item->save();
|
||||
|
||||
if ( ! $coupon_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_order_coupon', __( 'Cannot create coupon, try again.', 'woocommerce' ), 500 );
|
||||
}
|
||||
$order->add_item( $item );
|
||||
} else {
|
||||
|
||||
$item = new WC_Order_Item_Coupon( $coupon['id'] );
|
||||
|
|
|
@ -988,10 +988,15 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
$line_item->set_variation( $item['variations'] );
|
||||
}
|
||||
|
||||
$item_id = $line_item->save();
|
||||
// Save or add to order.
|
||||
if ( $creating ) {
|
||||
$order->add_item( $line_item );
|
||||
} else {
|
||||
$item_id = $line_item->save();
|
||||
|
||||
if ( ! $item_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_line_item', __( 'Cannot create line item, try again.', 'woocommerce' ), 500 );
|
||||
if ( ! $item_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_line_item', __( 'Cannot create line item, try again.', 'woocommerce' ), 500 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1073,11 +1078,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
$item = new WC_Order_Item_Shipping();
|
||||
$item->set_order_id( $order->get_id() );
|
||||
$item->set_shipping_rate( $rate );
|
||||
$shipping_id = $item->save();
|
||||
|
||||
if ( ! $shipping_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_shipping', __( 'Cannot create shipping method, try again.', 'woocommerce' ), 500 );
|
||||
}
|
||||
$order->add_item( $item );
|
||||
} else {
|
||||
|
||||
$item = new WC_Order_Item_Shipping( $shipping['id'] );
|
||||
|
@ -1144,11 +1145,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
}
|
||||
}
|
||||
|
||||
$fee_id = $item->save();
|
||||
|
||||
if ( ! $fee_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_fee', __( 'Cannot create fee, try again.', 'woocommerce' ), 500 );
|
||||
}
|
||||
$order->add_item( $item );
|
||||
} else {
|
||||
|
||||
$item = new WC_Order_Item_Fee( $fee['id'] );
|
||||
|
@ -1207,11 +1204,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
'discount_tax' => 0,
|
||||
'order_id' => $order->get_id(),
|
||||
) );
|
||||
$coupon_id = $item->save();
|
||||
|
||||
if ( ! $coupon_id ) {
|
||||
throw new WC_API_Exception( 'woocommerce_cannot_create_order_coupon', __( 'Cannot create coupon, try again.', 'woocommerce' ), 500 );
|
||||
}
|
||||
$order->add_item( $item );
|
||||
} else {
|
||||
|
||||
$item = new WC_Order_Item_Coupon( $coupon['id'] );
|
||||
|
|
|
@ -200,39 +200,39 @@ class WC_Structured_Data {
|
|||
return;
|
||||
}
|
||||
|
||||
$markup_offer = array(
|
||||
'@type' => 'Offer',
|
||||
'priceCurrency' => $currency,
|
||||
'availability' => 'https://schema.org/' . $stock = ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
|
||||
'sku' => $product->get_sku(),
|
||||
'image' => wp_get_attachment_url( $product->get_image_id() ),
|
||||
'description' => $product->get_description(),
|
||||
'seller' => array(
|
||||
'@type' => 'Organization',
|
||||
'name' => $shop_name,
|
||||
'url' => $shop_url,
|
||||
),
|
||||
);
|
||||
if ( '' !== $product->get_price() ) {
|
||||
$markup_offer = array(
|
||||
'@type' => 'Offer',
|
||||
'priceCurrency' => $currency,
|
||||
'availability' => 'https://schema.org/' . $stock = ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
|
||||
'sku' => $product->get_sku(),
|
||||
'image' => wp_get_attachment_url( $product->get_image_id() ),
|
||||
'description' => $product->get_description(),
|
||||
'seller' => array(
|
||||
'@type' => 'Organization',
|
||||
'name' => $shop_name,
|
||||
'url' => $shop_url,
|
||||
),
|
||||
);
|
||||
|
||||
if ( $product->is_type( 'variable' ) ) {
|
||||
$prices = $product->get_variation_prices();
|
||||
if ( $product->is_type( 'variable' ) ) {
|
||||
$prices = $product->get_variation_prices();
|
||||
|
||||
if ( current( $prices['price'] ) === end( $prices['price'] ) ) {
|
||||
$markup_offer['price'] = wc_format_decimal( $product->get_price(), wc_get_price_decimals() );
|
||||
if ( current( $prices['price'] ) === end( $prices['price'] ) ) {
|
||||
$markup_offer['price'] = wc_format_decimal( $product->get_price(), wc_get_price_decimals() );
|
||||
} else {
|
||||
$markup_offer['priceSpecification'] = array(
|
||||
'price' => wc_format_decimal( $product->get_price(), wc_get_price_decimals() ),
|
||||
'minPrice' => wc_format_decimal( current( $prices['price'] ), wc_get_price_decimals() ),
|
||||
'maxPrice' => wc_format_decimal( end( $prices['price'] ), wc_get_price_decimals() ),
|
||||
'priceCurrency' => $currency,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$markup_offer['priceSpecification'] = array(
|
||||
'price' => wc_format_decimal( $product->get_price(), wc_get_price_decimals() ),
|
||||
'minPrice' => wc_format_decimal( current( $prices['price'] ), wc_get_price_decimals() ),
|
||||
'maxPrice' => wc_format_decimal( end( $prices['price'] ), wc_get_price_decimals() ),
|
||||
'priceCurrency' => $currency,
|
||||
);
|
||||
$markup_offer['price'] = wc_format_decimal( $product->get_price(), wc_get_price_decimals() );
|
||||
}
|
||||
} else {
|
||||
$markup_offer['price'] = wc_format_decimal( $product->get_price(), wc_get_price_decimals() );
|
||||
}
|
||||
|
||||
$markup['offers'] = array( apply_filters( 'woocommerce_structured_data_product_offer', $markup_offer, $product ) );
|
||||
|
||||
if ( $product->get_rating_count() ) {
|
||||
$markup['aggregateRating'] = array(
|
||||
'@type' => 'AggregateRating',
|
||||
|
@ -402,7 +402,7 @@ class WC_Structured_Data {
|
|||
$markup = array();
|
||||
$markup['@type'] = 'Order';
|
||||
$markup['url'] = $order_url;
|
||||
$markup['orderStatus'] = isset( $order_status[ $order->get_status() ] ) ? $order_status[ $order->get_status() ] : '';
|
||||
$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;
|
||||
|
|
|
@ -997,50 +997,46 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
public function get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit ) {
|
||||
global $wpdb;
|
||||
|
||||
// Arrays to string.
|
||||
$exclude_ids = implode( ',', array_map( 'absint', $exclude_ids ) );
|
||||
$cats_array = implode( ',', array_map( 'absint', $cats_array ) );
|
||||
$tags_array = implode( ',', array_map( 'absint', $tags_array ) );
|
||||
|
||||
$limit = absint( $limit );
|
||||
$query = array();
|
||||
$query['fields'] = "SELECT DISTINCT ID FROM {$wpdb->posts} p";
|
||||
$query['join'] = " INNER JOIN {$wpdb->term_relationships} tr ON (p.ID = tr.object_id)";
|
||||
$query['join'] .= " INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)";
|
||||
$query['join'] .= " INNER JOIN {$wpdb->terms} t ON (t.term_id = tt.term_id)";
|
||||
$query['where'] = ' WHERE 1=1';
|
||||
$query['where'] .= " AND p.post_status = 'publish'";
|
||||
$query['where'] .= " AND p.post_type = 'product'";
|
||||
$query['where'] .= " AND p.ID NOT IN ( {$exclude_ids} )";
|
||||
|
||||
$include_term_ids = array_merge( $cats_array, $tags_array );
|
||||
$exclude_term_ids = array();
|
||||
$product_visibility_term_ids = wc_get_product_visibility_term_ids();
|
||||
|
||||
if ( $product_visibility_term_ids['exclude-from-catalog'] ) {
|
||||
$query['where'] .= " AND t.term_id !=" . $product_visibility_term_ids['exclude-from-catalog'];
|
||||
$exclude_term_ids[] = $product_visibility_term_ids['exclude-from-catalog'];
|
||||
}
|
||||
|
||||
if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && $product_visibility_term_ids['outofstock'] ) {
|
||||
$query['where'] .= " AND t.term_id !=" . $product_visibility_term_ids['outofstock'];
|
||||
$exclude_term_ids[] = $product_visibility_term_ids['outofstock'];
|
||||
}
|
||||
|
||||
if ( $cats_array || $tags_array ) {
|
||||
$query['where'] .= ' AND (';
|
||||
$query = array(
|
||||
'fields' => "
|
||||
SELECT DISTINCT ID FROM {$wpdb->posts} p
|
||||
",
|
||||
'join' => '',
|
||||
'where' => "
|
||||
WHERE 1=1
|
||||
AND p.post_status = 'publish'
|
||||
AND p.post_type = 'product'
|
||||
|
||||
if ( $cats_array ) {
|
||||
$query['where'] .= " ( tt.taxonomy = 'product_cat' AND t.term_id IN ( {$cats_array} ) ) ";
|
||||
if ( $tags_array ) {
|
||||
$query['where'] .= ' OR ';
|
||||
}
|
||||
}
|
||||
",
|
||||
'limits' => "
|
||||
LIMIT " . absint( $limit ) . "
|
||||
",
|
||||
);
|
||||
|
||||
if ( $tags_array ) {
|
||||
$query['where'] .= " ( tt.taxonomy = 'product_tag' AND t.term_id IN ( {$tags_array} ) ) ";
|
||||
}
|
||||
|
||||
$query['where'] .= ')';
|
||||
if ( $exclude_term_ids ) {
|
||||
$query['join'] .= " LEFT JOIN ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', array_map( 'absint', $exclude_term_ids ) ) . " ) ) AS exclude_join ON exclude_join.object_id = p.ID";
|
||||
$query['where'] .= " AND exclude_join.object_id IS NULL";
|
||||
}
|
||||
|
||||
$query['limits'] = " LIMIT {$limit} ";
|
||||
if ( $include_term_ids ) {
|
||||
$query['join'] .= " INNER JOIN ( SELECT object_id FROM {$wpdb->term_relationships} LEFT JOIN wp_term_taxonomy AS tax using( term_taxonomy_id ) WHERE term_id IN ( " . implode( ',', array_map( 'absint', $include_term_ids ) ) . " ) ) AS include_join ON include_join.object_id = p.ID";
|
||||
}
|
||||
|
||||
if ( $exclude_ids ) {
|
||||
$query['where'] .= " AND p.ID NOT IN ( " . implode( ',', array_map( 'absint', $exclude_ids ) ) . " )";
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
|
|
@ -280,7 +280,7 @@ class WC_Email extends WC_Settings_API {
|
|||
public function get_headers() {
|
||||
$header = "Content-Type: " . $this->get_content_type() . "\r\n";
|
||||
|
||||
if ( 'new_order' === $this->id ) {
|
||||
if ( 'new_order' === $this->id && $this->object && $this->object->get_billing_email() && ( $this->object->get_billing_first_name() || $this->object->get_billing_last_name() ) ) {
|
||||
$header .= 'Reply-to: ' . $this->object->get_billing_first_name() . ' ' . $this->object->get_billing_last_name() . ' <' . $this->object->get_billing_email() . ">\r\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -707,7 +707,7 @@ function wc_get_product_attachment_props( $attachment_id = null, $product = fals
|
|||
$props['alt'] = trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
|
||||
|
||||
// Large version.
|
||||
$src = wp_get_attachment_image_src( $attachment_id, 'large' );
|
||||
$src = wp_get_attachment_image_src( $attachment_id, 'full' );
|
||||
$props['full_src'] = $src[0];
|
||||
$props['full_src_w'] = $src[1];
|
||||
$props['full_src_h'] = $src[2];
|
||||
|
|
|
@ -106,6 +106,18 @@ function wc_prevent_adjacent_posts_rel_link_wp_head() {
|
|||
}
|
||||
add_action( 'template_redirect', 'wc_prevent_adjacent_posts_rel_link_wp_head' );
|
||||
|
||||
/**
|
||||
* Show the gallery if JS is disabled.
|
||||
*
|
||||
* @since 3.0.6
|
||||
*/
|
||||
function wc_gallery_noscript() {
|
||||
?>
|
||||
<noscript><style>.woocommerce-product-gallery{ opacity: 1 !important; }</style></noscript>
|
||||
<?php
|
||||
}
|
||||
add_action( 'wp_head', 'wc_gallery_noscript' );
|
||||
|
||||
/**
|
||||
* When the_post is called, put product data into a global.
|
||||
*
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.0.3
|
||||
* @version 3.0.6
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
|
@ -28,12 +28,13 @@ do_action( 'woocommerce_before_add_to_cart_form' ); ?>
|
|||
<tbody>
|
||||
<?php
|
||||
$quantites_required = false;
|
||||
$previous_post = $post;
|
||||
|
||||
foreach ( $grouped_products as $grouped_product ) {
|
||||
$post_object = get_post( $grouped_product->get_id() );
|
||||
$quantites_required = $quantites_required || ( $grouped_product->is_purchasable() && ! $grouped_product->has_options() );
|
||||
|
||||
setup_postdata( $GLOBALS['post'] =& $post_object );
|
||||
setup_postdata( $post =& $post_object );
|
||||
?>
|
||||
<tr id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
|
||||
<td>
|
||||
|
@ -79,7 +80,7 @@ do_action( 'woocommerce_before_add_to_cart_form' ); ?>
|
|||
</tr>
|
||||
<?php
|
||||
}
|
||||
wp_reset_postdata();
|
||||
$post = $previous_post;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -272,6 +272,29 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
|
|||
$object->save();
|
||||
$this->assertCount( 2, $object->get_items() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test: get_different_items
|
||||
*/
|
||||
function test_get_different_items() {
|
||||
$object = new WC_Order();
|
||||
$item_1 = new WC_Order_Item_Product();
|
||||
$item_1->set_props( array(
|
||||
'product' => WC_Helper_Product::create_simple_product(),
|
||||
'quantity' => 4,
|
||||
) );
|
||||
$item_2 = new WC_Order_Item_Fee();
|
||||
$item_2->set_props( array(
|
||||
'name' => 'Some Fee',
|
||||
'tax_status' => 'taxable',
|
||||
'total' => '100',
|
||||
'tax_class' => '',
|
||||
) );
|
||||
$object->add_item( $item_1 );
|
||||
$object->add_item( $item_2 );
|
||||
// $object->save();
|
||||
$this->assertCount( 2, $object->get_items( array( 'line_item', 'fee' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test: get_fees
|
||||
|
|
Loading…
Reference in New Issue