[Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes * Stock functions * Variation class * Bulk change ->id to get_id() to fix variation form display * Missing status * Fix add to cart * Start on stored data save * save variation * Save_variations * Variation edit panel * Save variations code works. * Remove stored data code and fix save * Improve legacy class * wc_bool_to_string * prepare_set_attributes * Use wc_get_products * More feedback fixes * Feedback fixes
This commit is contained in:
parent
91ddc7ecbd
commit
db0ce210a3
File diff suppressed because one or more lines are too long
|
@ -3777,6 +3777,7 @@ img.help_tip {
|
|||
}
|
||||
|
||||
textarea {
|
||||
float: left;
|
||||
height: 3.5em;
|
||||
line-height: 1.5em;
|
||||
vertical-align: top;
|
||||
|
@ -4189,8 +4190,8 @@ img.help_tip {
|
|||
|
||||
.upload_image_button {
|
||||
display: block;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
float: left;
|
||||
margin-right: 20px;
|
||||
position: relative;
|
||||
|
@ -4211,8 +4212,8 @@ img.help_tip {
|
|||
right: 0;
|
||||
bottom: 0;
|
||||
text-align: center;
|
||||
line-height: 48px;
|
||||
font-size: 48px;
|
||||
line-height: 64px;
|
||||
font-size: 64px;
|
||||
font-weight: 400;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
@ -4246,49 +4247,67 @@ img.help_tip {
|
|||
}
|
||||
|
||||
input[type=checkbox] {
|
||||
margin-top: 5px;
|
||||
margin-right: 3px;
|
||||
margin: -3px 0 0 .5em;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-row {
|
||||
label {
|
||||
display: block;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.woocommerce-help-tip {
|
||||
float: right;
|
||||
}
|
||||
|
||||
input[type=text],
|
||||
input[type=number],
|
||||
select {
|
||||
select,
|
||||
textarea {
|
||||
width: 100%;
|
||||
vertical-align: middle;
|
||||
margin: 2px 0 0;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
select {
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
&.dimensions_field {
|
||||
.wrap {
|
||||
clear:left;
|
||||
display: block;
|
||||
}
|
||||
input {
|
||||
width: 25%;
|
||||
width: 33%;
|
||||
float: left;
|
||||
margin-right: 1%;
|
||||
vertical-align: middle;
|
||||
|
||||
&:last-of-type {
|
||||
margin-right: 0;
|
||||
width: 34%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-row-first,
|
||||
.form-row-last {
|
||||
width: 48%;
|
||||
float: right;
|
||||
}
|
||||
&.form-row-first,
|
||||
&.form-row-last {
|
||||
width: 48%;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.form-row-first {
|
||||
clear: both;
|
||||
float: left;
|
||||
}
|
||||
&.form-row-first {
|
||||
clear: both;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.form-row-full {
|
||||
clear: both;
|
||||
&.form-row-full {
|
||||
clear: both;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -151,7 +151,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
|
|||
// Handly qty if set
|
||||
if ( isset( $args['qty'] ) ) {
|
||||
if ( $product->backorders_require_notification() && $product->is_on_backorder( $args['qty'] ) ) {
|
||||
$item->add_meta_data( apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $args['qty'] - max( 0, $product->get_total_stock() ), true );
|
||||
$item->add_meta_data( apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $args['qty'] - max( 0, $product->get_stock_quantity() ), true );
|
||||
}
|
||||
$args['subtotal'] = $args['subtotal'] ? $args['subtotal'] : $product->get_price_excluding_tax( $args['qty'] );
|
||||
$args['total'] = $args['total'] ? $args['total'] : $product->get_price_excluding_tax( $args['qty'] );
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy Abstract Product
|
||||
*
|
||||
|
@ -11,16 +15,252 @@
|
|||
* @category Abstract Class
|
||||
* @author WooThemes
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy Abstract Product class.
|
||||
*/
|
||||
abstract class WC_Abstract_Legacy_Product extends WC_Data {
|
||||
|
||||
/**
|
||||
* The product's type (simple, variable etc).
|
||||
* @deprecated 2.7.0 get_type() method should return string instead since this prop should not be changed or be public.
|
||||
* @var string
|
||||
*/
|
||||
public $product_type = 'simple';
|
||||
|
||||
/**
|
||||
* Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
|
||||
*
|
||||
* @param string $key Key name.
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset( $key ) {
|
||||
return
|
||||
in_array( $key, array_merge( array(
|
||||
'variation_id',
|
||||
'variation_data',
|
||||
'variation_has_stock',
|
||||
'variation_shipping_class_id',
|
||||
'product_attributes',
|
||||
'visibility',
|
||||
'sale_price_dates_from',
|
||||
'sale_price_dates_to',
|
||||
'post',
|
||||
'download_type',
|
||||
'product_image_gallery',
|
||||
'variation_shipping_class',
|
||||
'shipping_class',
|
||||
'total_stock',
|
||||
'crosssell_ids',
|
||||
'parent',
|
||||
), array_keys( $this->data ) ) ) || metadata_exists( 'post', $this->get_id(), '_' . $key ) || metadata_exists( 'post', $this->get_parent_id(), '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic __get method for backwards compatibility. Maps legacy vars to new getters.
|
||||
*
|
||||
* @param string $key Key name.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get( $key ) {
|
||||
_doing_it_wrong( $key, __( 'Product properties should not be accessed directly.', 'woocommerce' ), '2.7' );
|
||||
|
||||
switch ( $key ) {
|
||||
case 'id' :
|
||||
$value = $this->is_type( 'variation' ) ? $this->get_parent_id() : $this->get_id();
|
||||
break;
|
||||
case 'variation_id' :
|
||||
$value = $this->get_id();
|
||||
break;
|
||||
case 'product_attributes' :
|
||||
$value = isset( $this->data['attributes'] ) ? $this->data['attributes'] : '';
|
||||
break;
|
||||
case 'visibility' :
|
||||
$value = $this->get_catalog_visibility();
|
||||
break;
|
||||
case 'sale_price_dates_from' :
|
||||
$value = $this->get_date_on_sale_from();
|
||||
break;
|
||||
case 'sale_price_dates_to' :
|
||||
$value = $this->get_date_on_sale_to();
|
||||
break;
|
||||
case 'post' :
|
||||
$value = get_post( $this->get_id() );
|
||||
break;
|
||||
case 'download_type' :
|
||||
return 'standard';
|
||||
break;
|
||||
case 'product_image_gallery' :
|
||||
$value = $this->get_gallery_image_ids();
|
||||
break;
|
||||
case 'variation_shipping_class' :
|
||||
case 'shipping_class' :
|
||||
$value = $this->get_shipping_class();
|
||||
break;
|
||||
case 'total_stock' :
|
||||
$value = $this->get_total_stock();
|
||||
break;
|
||||
case 'downloadable' :
|
||||
case 'virtual' :
|
||||
case 'manage_stock' :
|
||||
case 'featured' :
|
||||
case 'sold_individually' :
|
||||
$value = $this->{"get_$key"}() ? 'yes' : 'no';
|
||||
break;
|
||||
case 'crosssell_ids' :
|
||||
$value = $this->get_cross_sell_ids();
|
||||
break;
|
||||
case 'upsell_ids' :
|
||||
$value = $this->get_upsell_ids();
|
||||
break;
|
||||
case 'parent' :
|
||||
$value = wc_get_product( $this->get_parent_id() );
|
||||
break;
|
||||
case 'variation_data' :
|
||||
$value = wc_get_product_variation_attributes( $this->get_id() );
|
||||
break;
|
||||
case 'variation_has_stock' :
|
||||
$value = $this->managing_stock();
|
||||
break;
|
||||
case 'variation_shipping_class_id' :
|
||||
$value = $this->get_shipping_class_id();
|
||||
break;
|
||||
default :
|
||||
if ( in_array( $key, array_keys( $this->data ) ) ) {
|
||||
$value = $this->{"get_$key"}();
|
||||
} else {
|
||||
$value = get_post_meta( $this->id, '_' . $key, true );
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the gallery attachment ids.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_gallery_attachment_ids() {
|
||||
_deprecated_function( 'WC_Product::get_gallery_attachment_ids', '2.7', 'WC_Product::get_gallery_image_ids' );
|
||||
return $this->get_gallery_image_ids();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set stock level of the product.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
*/
|
||||
public function set_stock( $amount = null, $mode = 'set' ) {
|
||||
_deprecated_function( 'WC_Product::set_stock', '2.7', 'wc_update_product_stock' );
|
||||
return wc_update_product_stock( $this, $amount, $mode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce stock level of the product.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @param int $amount Amount to reduce by. Default: 1
|
||||
* @return int new stock level
|
||||
*/
|
||||
public function reduce_stock( $amount = 1 ) {
|
||||
_deprecated_function( 'WC_Product::reduce_stock', '2.7', 'wc_update_product_stock' );
|
||||
wc_update_product_stock( $this, $amount, 'subtract' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase stock level of the product.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @param int $amount Amount to increase by. Default 1.
|
||||
* @return int new stock level
|
||||
*/
|
||||
public function increase_stock( $amount = 1 ) {
|
||||
_deprecated_function( 'WC_Product::increase_stock', '2.7', 'wc_update_product_stock' );
|
||||
wc_update_product_stock( $this, $amount, 'add' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stock status needs changing.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
*/
|
||||
public function check_stock_status() {
|
||||
_deprecated_function( 'WC_Product::check_stock_status', '2.7', 'wc_check_product_stock_status' );
|
||||
wc_check_product_stock_status( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the availability of the product.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_availability() {
|
||||
_deprecated_function( 'WC_Product::get_availability', '2.7', 'Handled in stock.php template file and wc_format_stock_for_display function.' );
|
||||
return apply_filters( 'woocommerce_get_availability', array(
|
||||
'availability' => $this->get_availability_text(),
|
||||
'class' => $this->get_availability_class(),
|
||||
), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get availability text based on stock status.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return string
|
||||
*/
|
||||
protected function get_availability_text() {
|
||||
_deprecated_function( 'WC_Product::get_availability_text', '2.7' );
|
||||
if ( ! $this->is_in_stock() ) {
|
||||
$availability = __( 'Out of stock', 'woocommerce' );
|
||||
} elseif ( $this->managing_stock() && $this->is_on_backorder( 1 ) ) {
|
||||
$availability = $this->backorders_require_notification() ? __( 'Available on backorder', 'woocommerce' ) : __( 'In stock', 'woocommerce' );
|
||||
} elseif ( $this->managing_stock() ) {
|
||||
switch ( get_option( 'woocommerce_stock_format' ) ) {
|
||||
case 'no_amount' :
|
||||
$availability = __( 'In stock', 'woocommerce' );
|
||||
break;
|
||||
case 'low_amount' :
|
||||
if ( $this->get_total_stock() <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
|
||||
$availability = sprintf( __( 'Only %s left in stock', 'woocommerce' ), $this->get_total_stock() );
|
||||
|
||||
if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
|
||||
$availability .= ' ' . __( '(also available on backorder)', 'woocommerce' );
|
||||
}
|
||||
} else {
|
||||
$availability = __( 'In stock', 'woocommerce' );
|
||||
}
|
||||
break;
|
||||
default :
|
||||
$availability = sprintf( __( '%s in stock', 'woocommerce' ), $this->get_total_stock() );
|
||||
|
||||
if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
|
||||
$availability .= ' ' . __( '(also available on backorder)', 'woocommerce' );
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$availability = '';
|
||||
}
|
||||
return apply_filters( 'woocommerce_get_availability_text', $availability, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get availability classname based on stock status.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return string
|
||||
*/
|
||||
protected function get_availability_class() {
|
||||
_deprecated_function( 'WC_Product::get_availability_class', '2.7' );
|
||||
if ( ! $this->is_in_stock() ) {
|
||||
$class = 'out-of-stock';
|
||||
} elseif ( $this->managing_stock() && $this->is_on_backorder( 1 ) && $this->backorders_require_notification() ) {
|
||||
$class = 'available-on-backorder';
|
||||
} else {
|
||||
$class = 'in-stock';
|
||||
}
|
||||
return apply_filters( 'woocommerce_get_availability_class', $class, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and return related products.
|
||||
* @deprecated 2.7.0 Use wc_get_related_products instead.
|
||||
|
@ -185,176 +425,6 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
|
|||
return wc_get_product_tag_list( $this->get_id(), $sep, $before, $after );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the availability of the product.
|
||||
*
|
||||
* If stock management is enabled at global and product level, a stock message
|
||||
* will be shown. e.g. In stock, In stock x10, Out of stock.
|
||||
*
|
||||
* If stock management is disabled at global or product level, out of stock
|
||||
* will be shown when needed, but in stock will be hidden from view.
|
||||
*
|
||||
* This can all be changed through use of the woocommerce_get_availability filter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_availability() {
|
||||
return apply_filters( 'woocommerce_get_availability', array(
|
||||
'availability' => $this->get_availability_text(),
|
||||
'class' => $this->get_availability_class(),
|
||||
), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get availability text based on stock status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_availability_text() {
|
||||
if ( ! $this->is_in_stock() ) {
|
||||
$availability = __( 'Out of stock', 'woocommerce' );
|
||||
} elseif ( $this->managing_stock() && $this->is_on_backorder( 1 ) ) {
|
||||
$availability = $this->backorders_require_notification() ? __( 'Available on backorder', 'woocommerce' ) : __( 'In stock', 'woocommerce' );
|
||||
} elseif ( $this->managing_stock() ) {
|
||||
switch ( get_option( 'woocommerce_stock_format' ) ) {
|
||||
case 'no_amount' :
|
||||
$availability = __( 'In stock', 'woocommerce' );
|
||||
break;
|
||||
case 'low_amount' :
|
||||
if ( $this->get_total_stock() <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
|
||||
$availability = sprintf( __( 'Only %s left in stock', 'woocommerce' ), $this->get_total_stock() );
|
||||
|
||||
if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
|
||||
$availability .= ' ' . __( '(also available on backorder)', 'woocommerce' );
|
||||
}
|
||||
} else {
|
||||
$availability = __( 'In stock', 'woocommerce' );
|
||||
}
|
||||
break;
|
||||
default :
|
||||
$availability = sprintf( __( '%s in stock', 'woocommerce' ), $this->get_total_stock() );
|
||||
|
||||
if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
|
||||
$availability .= ' ' . __( '(also available on backorder)', 'woocommerce' );
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$availability = '';
|
||||
}
|
||||
return apply_filters( 'woocommerce_get_availability_text', $availability, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get availability classname based on stock status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_availability_class() {
|
||||
if ( ! $this->is_in_stock() ) {
|
||||
$class = 'out-of-stock';
|
||||
} elseif ( $this->managing_stock() && $this->is_on_backorder( 1 ) && $this->backorders_require_notification() ) {
|
||||
$class = 'available-on-backorder';
|
||||
} else {
|
||||
$class = 'in-stock';
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_availability_class', $class, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* The product's type (simple, variable etc).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $product_type = null;
|
||||
|
||||
/**
|
||||
* Product shipping class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $shipping_class = '';
|
||||
|
||||
/**
|
||||
* ID of the shipping class this product has.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $shipping_class_id = 0;
|
||||
|
||||
/** @public string The product's total stock, including that of its children. */
|
||||
public $total_stock;
|
||||
|
||||
|
||||
/**
|
||||
* Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
|
||||
*
|
||||
* @param string $key Key name.
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset( $key ) {
|
||||
return metadata_exists( 'post', $this->id, '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic __get method for backwards compatibility.Maps legacy vars to new getters.
|
||||
*
|
||||
* @param string $key Key name.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get( $key ) {
|
||||
_doing_it_wrong( $key, __( 'Product properties should not be accessed directly.', 'woocommerce' ), '2.7' );
|
||||
|
||||
switch ( $key ) {
|
||||
case 'id' :
|
||||
$value = $this->get_id();
|
||||
break;
|
||||
case 'product_attributes' :
|
||||
$value = isset( $this->data['attributes'] ) ? $this->data['attributes'] : '';
|
||||
break;
|
||||
case 'visibility' :
|
||||
$value = $this->get_catalog_visibility();
|
||||
break;
|
||||
case 'sale_price_dates_from' :
|
||||
$value = $this->get_date_on_sale_from();
|
||||
break;
|
||||
case 'sale_price_dates_to' :
|
||||
$value = $this->get_date_on_sale_to();
|
||||
break;
|
||||
case 'post' :
|
||||
$value = get_post( $this->get_id() );
|
||||
break;
|
||||
case 'product_type' : // @todo What do we do with 3rd party use of product_type now it's hardcoded?
|
||||
$value = $this->get_type();
|
||||
break;
|
||||
case 'download_type' :
|
||||
return 'standard';
|
||||
break;
|
||||
case 'product_image_gallery' :
|
||||
$value = $this->get_gallery_attachment_ids();
|
||||
break;
|
||||
default :
|
||||
$value = get_post_meta( $this->id, '_' . $key, true );
|
||||
|
||||
// Get values or default if not set.
|
||||
if ( in_array( $key, array( 'downloadable', 'virtual', 'backorders', 'manage_stock', 'featured', 'sold_individually' ) ) ) {
|
||||
$value = $value ? $value : 'no';
|
||||
} elseif ( in_array( $key, array( 'product_attributes', 'crosssell_ids', 'upsell_ids' ) ) ) {
|
||||
$value = $value ? $value : array();
|
||||
} elseif ( 'stock' === $key ) {
|
||||
$value = $value ? $value : 0;
|
||||
} elseif ( 'stock_status' === $key ) {
|
||||
$value = $value ? $value : 'instock';
|
||||
} elseif ( 'tax_status' === $key ) {
|
||||
$value = $value ? $value : 'taxable';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the product's post data.
|
||||
*
|
||||
|
@ -362,6 +432,7 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
|
|||
* @return WP_Post
|
||||
*/
|
||||
public function get_post_data() {
|
||||
_deprecated_function( 'WC_Product::get_post_data', '2.7', 'get_post' );
|
||||
return get_post( $this->get_id() );
|
||||
}
|
||||
|
||||
|
@ -421,4 +492,93 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variation ID.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return int
|
||||
*/
|
||||
public function get_variation_id() {
|
||||
_deprecated_function( 'WC_Product::get_variation_id', '2.7', 'WC_Product::get_id() will always be the variation ID if this is a variation.' );
|
||||
return $this->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product variation description.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_variation_description() {
|
||||
_deprecated_function( 'WC_Product::get_variation_description', '2.7', 'WC_Product::get_description()' );
|
||||
return $this->get_description();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if all variation's attributes are set.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function has_all_attributes_set() {
|
||||
_deprecated_function( 'WC_Product::has_all_attributes_set', '2.7' );
|
||||
$set = true;
|
||||
|
||||
// undefined attributes have null strings as array values
|
||||
foreach ( $this->get_variation_attributes() as $att ) {
|
||||
if ( ! $att ) {
|
||||
$set = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the variations parent is visible.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return bool
|
||||
*/
|
||||
public function parent_is_visible() {
|
||||
_deprecated_function( 'WC_Product::parent_is_visible', '2.7' );
|
||||
return $this->is_visible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total stock - This is the stock of parent and children combined.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return int
|
||||
*/
|
||||
public function get_total_stock() {
|
||||
_deprecated_function( 'WC_Product::get_total_stock', '2.7', 'Use get_stock_quantity on each child. Beware of performance issues in doing so.' );
|
||||
if ( empty( $this->total_stock ) ) {
|
||||
if ( sizeof( $this->get_children() ) > 0 ) {
|
||||
$this->total_stock = max( 0, $this->get_stock_quantity() );
|
||||
|
||||
foreach ( $this->get_children() as $child_id ) {
|
||||
if ( 'yes' === get_post_meta( $child_id, '_manage_stock', true ) ) {
|
||||
$stock = get_post_meta( $child_id, '_stock', true );
|
||||
$this->total_stock += max( 0, wc_stock_amount( $stock ) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->total_stock = $this->get_stock_quantity();
|
||||
}
|
||||
}
|
||||
return wc_stock_amount( $this->total_stock );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names.
|
||||
*
|
||||
* @deprecated 2.7.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_formatted_variation_attributes( $flat = false ) {
|
||||
_deprecated_function( 'WC_Product::get_formatted_variation_attributes', '2.7', 'wc_get_formatted_variation' );
|
||||
return wc_get_formatted_variation( $this->get_variation_attributes(), $flat );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1163,7 +1163,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
$shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
|
||||
|
||||
// Inherit tax class from items
|
||||
if ( '' === $shipping_tax_class ) {
|
||||
if ( 'inherit' === $shipping_tax_class ) {
|
||||
$tax_rates = array();
|
||||
$tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
|
||||
$found_tax_classes = $this->get_items_tax_classes();
|
||||
|
@ -1187,7 +1187,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
'state' => $args['state'],
|
||||
'postcode' => $args['postcode'],
|
||||
'city' => $args['city'],
|
||||
'tax_class' => 'standard' === $shipping_tax_class ? '' : $shipping_tax_class,
|
||||
'tax_class' => $shipping_tax_class,
|
||||
) );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,14 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy product contains all deprecated methods for this class and can be
|
||||
* removed in the future.
|
||||
*/
|
||||
include_once( 'abstract-wc-legacy-product.php' );
|
||||
|
||||
/**
|
||||
* Abstract Product Class
|
||||
*
|
||||
|
@ -9,69 +19,65 @@
|
|||
* @category Abstract Class
|
||||
* @author WooThemes
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
include_once( 'abstract-wc-legacy-product.php' );
|
||||
|
||||
/**
|
||||
* Product Class.
|
||||
*/
|
||||
class WC_Product extends WC_Abstract_Legacy_Product {
|
||||
|
||||
/**
|
||||
* Post type.
|
||||
* @var string
|
||||
*/
|
||||
protected $post_type = 'product';
|
||||
|
||||
/**
|
||||
* Stores product data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array(
|
||||
'name' => '',
|
||||
'slug' => '',
|
||||
'date_created' => '',
|
||||
'date_modified' => '',
|
||||
'status' => false,
|
||||
'featured' => false,
|
||||
'catalog_visibility' => 'hidden',
|
||||
'description' => '',
|
||||
'short_description' => '',
|
||||
'sku' => '',
|
||||
'price' => '',
|
||||
'regular_price' => '',
|
||||
'sale_price' => '',
|
||||
'date_on_sale_from' => '',
|
||||
'date_on_sale_to' => '',
|
||||
'total_sales' => '0',
|
||||
'tax_status' => 'taxable',
|
||||
'tax_class' => '',
|
||||
'manage_stock' => false,
|
||||
'stock_quantity' => null,
|
||||
'stock_status' => '',
|
||||
'backorders' => 'no',
|
||||
'sold_individually' => false,
|
||||
'weight' => '',
|
||||
'length' => '',
|
||||
'width' => '',
|
||||
'height' => '',
|
||||
'upsell_ids' => array(),
|
||||
'cross_sell_ids' => array(),
|
||||
'parent_id' => 0,
|
||||
'reviews_allowed' => true,
|
||||
'purchase_note' => '',
|
||||
'attributes' => array(),
|
||||
'default_attributes' => array(),
|
||||
'menu_order' => 0,
|
||||
'virtual' => false,
|
||||
'downloadable' => false,
|
||||
'category_ids' => array(),
|
||||
'tag_ids' => array(),
|
||||
'shipping_class_id' => 0,
|
||||
'downloads' => array(),
|
||||
'thumbnail_id' => '',
|
||||
'gallery_attachment_ids' => array(),
|
||||
'download_limit' => -1,
|
||||
'download_expiry' => -1,
|
||||
'name' => '',
|
||||
'slug' => '',
|
||||
'date_created' => '',
|
||||
'date_modified' => '',
|
||||
'status' => false,
|
||||
'featured' => false,
|
||||
'catalog_visibility' => 'hidden',
|
||||
'description' => '',
|
||||
'short_description' => '',
|
||||
'sku' => '',
|
||||
'price' => '',
|
||||
'regular_price' => '',
|
||||
'sale_price' => '',
|
||||
'date_on_sale_from' => '',
|
||||
'date_on_sale_to' => '',
|
||||
'total_sales' => '0',
|
||||
'tax_status' => 'taxable',
|
||||
'tax_class' => '',
|
||||
'manage_stock' => false,
|
||||
'stock_quantity' => null,
|
||||
'stock_status' => '',
|
||||
'backorders' => 'no',
|
||||
'sold_individually' => false,
|
||||
'weight' => '',
|
||||
'length' => '',
|
||||
'width' => '',
|
||||
'height' => '',
|
||||
'upsell_ids' => array(),
|
||||
'cross_sell_ids' => array(),
|
||||
'parent_id' => 0,
|
||||
'reviews_allowed' => true,
|
||||
'purchase_note' => '',
|
||||
'attributes' => array(),
|
||||
'default_attributes' => array(),
|
||||
'menu_order' => 0,
|
||||
'virtual' => false,
|
||||
'downloadable' => false,
|
||||
'category_ids' => array(),
|
||||
'tag_ids' => array(),
|
||||
'shipping_class_id' => 0,
|
||||
'downloads' => array(),
|
||||
'image_id' => '',
|
||||
'gallery_image_ids' => array(),
|
||||
'download_limit' => -1,
|
||||
'download_expiry' => -1,
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -145,20 +151,13 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
*/
|
||||
|
||||
/**
|
||||
* Get internal type.
|
||||
* Get internal type. Should return string and *should be overridden* by child classes.
|
||||
* @since 2.7.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_type() {
|
||||
return 'simple';
|
||||
}
|
||||
|
||||
/**
|
||||
* Product permalink.
|
||||
* @return string
|
||||
*/
|
||||
public function get_permalink() {
|
||||
return get_permalink( $this->get_id() );
|
||||
// product_type is @deprecated but here for BW compat with child classes.
|
||||
return $this->product_type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -327,11 +326,15 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
|
||||
/**
|
||||
* Returns the tax class.
|
||||
*
|
||||
* @param bool $raw Get unfiltered value.
|
||||
* @return string
|
||||
*/
|
||||
public function get_tax_class() {
|
||||
return apply_filters( 'woocommerce_product_tax_class', $this->data['tax_class'], $this );
|
||||
public function get_tax_class( $raw = false ) {
|
||||
if ( $raw ) {
|
||||
return $this->data['tax_class'];
|
||||
} else {
|
||||
return apply_filters( 'woocommerce_product_tax_class', $this->data['tax_class'], $this );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -350,7 +353,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return int|null
|
||||
*/
|
||||
public function get_stock_quantity() {
|
||||
return apply_filters( 'woocommerce_get_stock_quantity', $this->get_manage_stock() ? wc_stock_amount( $this->data['stock_quantity'] ) : null, $this );
|
||||
return apply_filters( 'woocommerce_get_stock_quantity', $this->get_manage_stock() ? $this->data['stock_quantity'] : null, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -389,11 +392,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return string
|
||||
*/
|
||||
public function get_weight() {
|
||||
// Legacy filter.
|
||||
$weight = apply_filters( 'woocommerce_product_weight', $this->data['weight'], $this ); // @todo standardize these filter names and move BW compat to deprecated class file.
|
||||
|
||||
// New filter.
|
||||
return apply_filters( 'woocommerce_product_get_weight', $weight, $this );
|
||||
return apply_filters( 'woocommerce_product_get_weight', $this->data['weight'], $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -402,11 +401,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return string
|
||||
*/
|
||||
public function get_length() {
|
||||
// Legacy filter.
|
||||
$length = apply_filters( 'woocommerce_product_length', $this->data['length'], $this );
|
||||
|
||||
// New filter since 2.7.
|
||||
return apply_filters( 'woocommerce_product_get_length', $length, $this );
|
||||
return apply_filters( 'woocommerce_product_get_length', $this->data['length'], $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -415,11 +410,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return string
|
||||
*/
|
||||
public function get_width() {
|
||||
// Legacy filter.
|
||||
$width = apply_filters( 'woocommerce_product_width', $this->data['width'], $this );
|
||||
|
||||
// New filter since 2.7.
|
||||
return apply_filters( 'woocommerce_product_get_width', $width, $this );
|
||||
return apply_filters( 'woocommerce_product_get_width', $this->data['width'], $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -428,11 +419,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return string
|
||||
*/
|
||||
public function get_height() {
|
||||
// Legacy filter.
|
||||
$height = apply_filters( 'woocommerce_product_height', $this->data['height'], $this );
|
||||
|
||||
// New filter since 2.7.
|
||||
return apply_filters( 'woocommerce_product_get_height', $height, $this );
|
||||
return apply_filters( 'woocommerce_product_get_height', $this->data['height'], $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -549,8 +536,8 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_gallery_attachment_ids() {
|
||||
return apply_filters( 'woocommerce_product_gallery_attachment_ids', array_filter( array_filter( $this->data['gallery_attachment_ids'] ), 'wp_attachment_is_image' ), $this );
|
||||
public function get_gallery_image_ids() {
|
||||
return apply_filters( 'woocommerce_product_gallery_attachment_ids', array_filter( array_filter( $this->data['gallery_image_ids'] ), 'wp_attachment_is_image' ), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -604,13 +591,13 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get thumbnail ID.
|
||||
* Get main image ID. @todo ensure read handles parent like get_image_id used to?
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_thumbnail_id() {
|
||||
return $this->data['thumbnail_id'];
|
||||
public function get_image_id() {
|
||||
return $this->data['image_id'];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -845,7 +832,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @param float|null $quantity Stock quantity.
|
||||
*/
|
||||
public function set_stock_quantity( $quantity ) {
|
||||
$this->data['stock_quantity'] = $quantity;
|
||||
$this->data['stock_quantity'] = '' !== $quantity ? wc_stock_amount( $quantity ) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -856,17 +843,12 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
public function set_stock_status( $status ) {
|
||||
$status = 'outofstock' === $status ? 'outofstock' : 'instock';
|
||||
|
||||
// Sanity check.
|
||||
if ( $this->managing_stock() ) {
|
||||
if ( ! $this->backorders_allowed() && $this->get_stock_quantity() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) {
|
||||
$status = 'outofstock';
|
||||
}
|
||||
}
|
||||
|
||||
if ( update_post_meta( $this->get_id(), '_stock_status', $status ) ) {
|
||||
do_action( 'woocommerce_product_set_stock_status', $this->get_id(), $status );
|
||||
}
|
||||
|
||||
$this->data['stock_status'] = $status;
|
||||
}
|
||||
|
||||
|
@ -1116,7 +1098,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
}
|
||||
}
|
||||
|
||||
// Validate the file exists
|
||||
// Validate the file exists.
|
||||
if ( 'relative' === $file_is ) {
|
||||
$_file_url = $file_url;
|
||||
if ( '..' === substr( $file_url, 0, 2 ) || '/' !== substr( $file_url, 0, 1 ) ) {
|
||||
|
@ -1168,18 +1150,18 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @since 2.7.0
|
||||
* @param array $gallery_ids
|
||||
*/
|
||||
public function set_gallery_attachment_ids( $gallery_ids ) {
|
||||
$this->data['gallery_attachment_ids'] = $gallery_ids;
|
||||
public function set_gallery_image_ids( $gallery_ids ) {
|
||||
$this->data['gallery_image_ids'] = $gallery_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set thumbnail ID.
|
||||
* Set main image ID.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param int $thumbnail_id
|
||||
* @param int $image_id
|
||||
*/
|
||||
public function set_thumbnail_id( $thumbnail_id = '' ) {
|
||||
$this->data['thumbnail_id'] = $thumbnail_id;
|
||||
public function set_image_id( $image_id = '' ) {
|
||||
$this->data['image_id'] = $image_id;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1244,51 +1226,50 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
|
||||
$this->set_id( $id );
|
||||
$this->set_props( array(
|
||||
'name' => get_the_title( $post_object ),
|
||||
'slug' => $post_object->post_name,
|
||||
'permalink' => get_permalink( $post_object ),
|
||||
'date_created' => $post_object->post_date,
|
||||
'date_modified' => $post_object->post_modified,
|
||||
'type' => '',
|
||||
'status' => $post_object->post_status,
|
||||
'featured' => get_post_meta( $id, '_featured', true ),
|
||||
'catalog_visibility' => get_post_meta( $id, '_visibility', true ),
|
||||
'description' => $post_object->post_content,
|
||||
'short_description' => $post_object->post_excerpt,
|
||||
'sku' => get_post_meta( $id, '_sku', true ),
|
||||
'regular_price' => get_post_meta( $id, '_regular_price', true ),
|
||||
'sale_price' => get_post_meta( $id, '_sale_price', true ),
|
||||
'date_on_sale_from' => get_post_meta( $id, '_sale_price_dates_from', true ),
|
||||
'date_on_sale_to' => get_post_meta( $id, '_sale_price_dates_to', true ),
|
||||
'total_sales' => get_post_meta( $id, 'total_sales', true ),
|
||||
'tax_status' => get_post_meta( $id, '_tax_status', true ),
|
||||
'tax_class' => get_post_meta( $id, '_tax_class', true ),
|
||||
'manage_stock' => get_post_meta( $id, '_manage_stock', true ),
|
||||
'stock_quantity' => get_post_meta( $id, '_stock', true ),
|
||||
'stock_status' => get_post_meta( $id, '_stock_status', true ),
|
||||
'backorders' => get_post_meta( $id, '_backorders', true ),
|
||||
'sold_individually' => get_post_meta( $id, '_sold_individually', true ),
|
||||
'weight' => get_post_meta( $id, '_weight', true ),
|
||||
'length' => get_post_meta( $id, '_length', true ),
|
||||
'width' => get_post_meta( $id, '_width', true ),
|
||||
'height' => get_post_meta( $id, '_height', true ),
|
||||
'upsell_ids' => get_post_meta( $id, '_upsell_ids', true ),
|
||||
'cross_sell_ids' => get_post_meta( $id, '_crosssell_ids', true ),
|
||||
'parent_id' => $post_object->post_parent,
|
||||
'reviews_allowed' => 'open' === $post_object->comment_status,
|
||||
'purchase_note' => get_post_meta( $id, '_purchase_note', true ),
|
||||
'default_attributes' => get_post_meta( $id, '_default_attributes', true ),
|
||||
'menu_order' => $post_object->menu_order,
|
||||
'category_ids' => $this->get_term_ids( 'product_cat' ),
|
||||
'tag_ids' => $this->get_term_ids( 'product_tag' ),
|
||||
'shipping_class_id' => current( $this->get_term_ids( 'product_shipping_class' ) ),
|
||||
'virtual' => get_post_meta( $id, '_virtual', true ),
|
||||
'downloadable' => get_post_meta( $id, '_downloadable', true ),
|
||||
'downloads' => array_filter( (array) get_post_meta( $id, '_downloadable_files', true ) ),
|
||||
'gallery_attachment_ids' => array_filter( explode( ',', get_post_meta( $id, '_product_image_gallery', true ) ) ),
|
||||
'download_limit' => get_post_meta( $id, '_download_limit', true ),
|
||||
'download_expiry' => get_post_meta( $id, '_download_expiry', true ),
|
||||
'thumbnail_id' => get_post_thumbnail_id( $id ),
|
||||
'name' => get_the_title( $post_object ),
|
||||
'slug' => $post_object->post_name,
|
||||
'date_created' => $post_object->post_date,
|
||||
'date_modified' => $post_object->post_modified,
|
||||
'type' => '',
|
||||
'status' => $post_object->post_status,
|
||||
'featured' => get_post_meta( $id, '_featured', true ),
|
||||
'catalog_visibility' => get_post_meta( $id, '_visibility', true ),
|
||||
'description' => $post_object->post_content,
|
||||
'short_description' => $post_object->post_excerpt,
|
||||
'sku' => get_post_meta( $id, '_sku', true ),
|
||||
'regular_price' => get_post_meta( $id, '_regular_price', true ),
|
||||
'sale_price' => get_post_meta( $id, '_sale_price', true ),
|
||||
'date_on_sale_from' => get_post_meta( $id, '_sale_price_dates_from', true ),
|
||||
'date_on_sale_to' => get_post_meta( $id, '_sale_price_dates_to', true ),
|
||||
'total_sales' => get_post_meta( $id, 'total_sales', true ),
|
||||
'tax_status' => get_post_meta( $id, '_tax_status', true ),
|
||||
'tax_class' => get_post_meta( $id, '_tax_class', true ),
|
||||
'manage_stock' => get_post_meta( $id, '_manage_stock', true ),
|
||||
'stock_quantity' => get_post_meta( $id, '_stock', true ),
|
||||
'stock_status' => get_post_meta( $id, '_stock_status', true ),
|
||||
'backorders' => get_post_meta( $id, '_backorders', true ),
|
||||
'sold_individually' => get_post_meta( $id, '_sold_individually', true ),
|
||||
'weight' => get_post_meta( $id, '_weight', true ),
|
||||
'length' => get_post_meta( $id, '_length', true ),
|
||||
'width' => get_post_meta( $id, '_width', true ),
|
||||
'height' => get_post_meta( $id, '_height', true ),
|
||||
'upsell_ids' => get_post_meta( $id, '_upsell_ids', true ),
|
||||
'cross_sell_ids' => get_post_meta( $id, '_crosssell_ids', true ),
|
||||
'parent_id' => $post_object->post_parent,
|
||||
'reviews_allowed' => 'open' === $post_object->comment_status,
|
||||
'purchase_note' => get_post_meta( $id, '_purchase_note', true ),
|
||||
'default_attributes' => get_post_meta( $id, '_default_attributes', true ),
|
||||
'menu_order' => $post_object->menu_order,
|
||||
'category_ids' => $this->get_term_ids( 'product_cat' ),
|
||||
'tag_ids' => $this->get_term_ids( 'product_tag' ),
|
||||
'shipping_class_id' => current( $this->get_term_ids( 'product_shipping_class' ) ),
|
||||
'virtual' => get_post_meta( $id, '_virtual', true ),
|
||||
'downloadable' => get_post_meta( $id, '_downloadable', true ),
|
||||
'downloads' => array_filter( (array) get_post_meta( $id, '_downloadable_files', true ) ),
|
||||
'gallery_image_ids' => array_filter( explode( ',', get_post_meta( $id, '_product_image_gallery', true ) ) ),
|
||||
'download_limit' => get_post_meta( $id, '_download_limit', true ),
|
||||
'download_expiry' => get_post_meta( $id, '_download_expiry', true ),
|
||||
'image_id' => get_post_thumbnail_id( $id ),
|
||||
) );
|
||||
if ( $this->is_on_sale() ) {
|
||||
$this->set_price( $this->get_sale_price() );
|
||||
|
@ -1340,7 +1321,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
$this->set_date_created( current_time( 'timestamp' ) );
|
||||
|
||||
$id = wp_insert_post( apply_filters( 'woocommerce_new_product_data', array(
|
||||
'post_type' => 'product',
|
||||
'post_type' => $this->post_type,
|
||||
'post_status' => $this->get_status() ? $this->get_status() : 'publish',
|
||||
'post_author' => get_current_user_id(),
|
||||
'post_title' => $this->get_name() ? $this->get_name() : __( 'Product', 'woocommerce' ),
|
||||
|
@ -1360,7 +1341,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
$this->update_terms();
|
||||
$this->update_attributes();
|
||||
$this->save_meta_data();
|
||||
do_action( 'woocommerce_new_product', $id );
|
||||
do_action( 'woocommerce_new_' . $this->post_type, $id );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1385,7 +1366,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
$this->update_terms();
|
||||
$this->update_attributes();
|
||||
$this->save_meta_data();
|
||||
do_action( 'woocommerce_update_product', $this->get_id() );
|
||||
do_action( 'woocommerce_update_' . $this->post_type, $this->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1406,6 +1387,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
// Version is set to current WC version to track data changes.
|
||||
update_post_meta( $this->get_id(), '_product_version', WC_VERSION );
|
||||
wc_delete_product_transients( $this->get_id() );
|
||||
return $this->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1415,7 +1397,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
*/
|
||||
public function delete() {
|
||||
wp_delete_post( $this->get_id() );
|
||||
do_action( 'woocommerce_delete_product', $this->get_id() );
|
||||
do_action( 'woocommerce_delete_' . $this->post_type, $this->get_id() );
|
||||
$this->set_id( 0 );
|
||||
}
|
||||
|
||||
|
@ -1425,54 +1407,93 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @since 2.7.0
|
||||
*/
|
||||
protected function update_post_meta() {
|
||||
$id = $this->get_id();
|
||||
update_post_meta( $id, '_visibility', $this->get_catalog_visibility() );
|
||||
update_post_meta( $id, '_sku', $this->get_sku() );
|
||||
update_post_meta( $id, '_regular_price', $this->get_regular_price() );
|
||||
update_post_meta( $id, '_sale_price', $this->get_sale_price() );
|
||||
update_post_meta( $id, '_sale_price_dates_from', $this->get_date_on_sale_from() );
|
||||
update_post_meta( $id, '_sale_price_dates_to', $this->get_date_on_sale_to() );
|
||||
update_post_meta( $id, 'total_sales', $this->get_total_sales() );
|
||||
update_post_meta( $id, '_tax_status', $this->get_tax_status() );
|
||||
update_post_meta( $id, '_tax_class', $this->get_tax_class() );
|
||||
update_post_meta( $id, '_manage_stock', $this->get_manage_stock() );
|
||||
update_post_meta( $id, '_stock', $this->get_stock_quantity() );
|
||||
update_post_meta( $id, '_stock_status', $this->get_stock_status() );
|
||||
update_post_meta( $id, '_backorders', $this->get_backorders() );
|
||||
update_post_meta( $id, '_sold_individually', $this->get_sold_individually() );
|
||||
update_post_meta( $id, '_weight', $this->get_weight() );
|
||||
update_post_meta( $id, '_length', $this->get_length() );
|
||||
update_post_meta( $id, '_width', $this->get_width() );
|
||||
update_post_meta( $id, '_height', $this->get_height() );
|
||||
update_post_meta( $id, '_upsell_ids', $this->get_upsell_ids() );
|
||||
update_post_meta( $id, '_crosssell_ids', $this->get_cross_sell_ids() );
|
||||
update_post_meta( $id, '_purchase_note', $this->get_purchase_note() );
|
||||
update_post_meta( $id, '_default_attributes', $this->get_default_attributes() );
|
||||
update_post_meta( $id, '_virtual', $this->get_virtual() ? 'yes' : 'no' );
|
||||
update_post_meta( $id, '_downloadable', $this->get_downloadable() ? 'yes' : 'no' );
|
||||
update_post_meta( $id, '_product_image_gallery', implode( ',', $this->get_gallery_attachment_ids() ) );
|
||||
update_post_meta( $id, '_download_limit', $this->get_download_limit() );
|
||||
update_post_meta( $id, '_download_expiry', $this->get_download_expiry() );
|
||||
$updated_props = array();
|
||||
$meta_key_to_props = array(
|
||||
'_visibility' => 'catalog_visibility',
|
||||
'_sku' => 'sku',
|
||||
'_regular_price' => 'regular_price',
|
||||
'_sale_price' => 'sale_price',
|
||||
'_sale_price_dates_from' => 'date_on_sale_from',
|
||||
'_sale_price_dates_to' => 'date_on_sale_to',
|
||||
'total_sales' => 'total_sales',
|
||||
'_tax_status' => 'tax_status',
|
||||
'_tax_class' => 'tax_class',
|
||||
'_manage_stock' => 'manage_stock',
|
||||
'_backorders' => 'backorders',
|
||||
'_sold_individually' => 'sold_individually',
|
||||
'_weight' => 'weight',
|
||||
'_length' => 'length',
|
||||
'_width' => 'width',
|
||||
'_height' => 'height',
|
||||
'_upsell_ids' => 'upsell_ids',
|
||||
'_crosssell_ids' => 'cross_sell_ids',
|
||||
'_purchase_note' => 'purchase_note',
|
||||
'_default_attributes' => 'default_attributes',
|
||||
'_virtual' => 'virtual',
|
||||
'_downloadable' => 'downloadable',
|
||||
'_product_image_gallery' => 'gallery_image_ids',
|
||||
'_download_limit' => 'download_limit',
|
||||
'_download_expiry' => 'download_expiry',
|
||||
'_featured' => 'featured',
|
||||
'_thumbnail_id' => 'image_id',
|
||||
'_downloadable_files' => 'downloads',
|
||||
'_stock' => 'stock_quantity',
|
||||
'_stock_status' => 'stock_status',
|
||||
);
|
||||
|
||||
if ( update_post_meta( $id, '_featured', $this->get_featured() ) ) {
|
||||
delete_transient( 'wc_featured_products' );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->get_thumbnail_id() ) ) {
|
||||
set_post_thumbnail( $id, $this->get_thumbnail_id() );
|
||||
} else {
|
||||
delete_post_meta( $id, '_thumbnail_id' );
|
||||
foreach ( $meta_key_to_props as $meta_key => $prop ) {
|
||||
$value = $this->data[ $prop ];
|
||||
// @todo this is where state should be checked?
|
||||
switch ( $prop ) {
|
||||
case 'virtual' :
|
||||
case 'downloadable' :
|
||||
$updated = update_post_meta( $this->get_id(), $meta_key, wc_bool_to_string( $value ) );
|
||||
break;
|
||||
case 'gallery_image_ids' :
|
||||
$updated = update_post_meta( $this->get_id(), $meta_key, implode( ',', $value ) );
|
||||
break;
|
||||
case 'image_id' :
|
||||
if ( ! empty( $value ) ) {
|
||||
set_post_thumbnail( $this->get_id(), $value );
|
||||
} else {
|
||||
delete_post_meta( $this->get_id(), '_thumbnail_id' );
|
||||
}
|
||||
$updated = true;
|
||||
break;
|
||||
default :
|
||||
$updated = update_post_meta( $this->get_id(), $meta_key, $value );
|
||||
break;
|
||||
}
|
||||
if ( $updated ) {
|
||||
$updated_props[] = $prop;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->is_on_sale() ) {
|
||||
update_post_meta( $id, '_price', $this->get_sale_price() );
|
||||
update_post_meta( $this->get_id(), '_price', $this->get_sale_price() );
|
||||
} else {
|
||||
update_post_meta( $id, '_price', $this->get_regular_price() );
|
||||
update_post_meta( $this->get_id(), '_price', $this->get_regular_price() );
|
||||
}
|
||||
|
||||
if ( update_post_meta( $id, '_downloadable_files', $this->get_downloads() ) ) {
|
||||
// grant permission to any newly added files on any existing orders for this product prior to saving @todo hook for variations?
|
||||
do_action( 'woocommerce_process_product_file_download_paths', $id, 0, $this->get_downloads() );
|
||||
if ( in_array( 'featured', $updated_props ) ) {
|
||||
delete_transient( 'wc_featured_products' );
|
||||
}
|
||||
|
||||
if ( in_array( 'downloads', $updated_props ) ) {
|
||||
// grant permission to any newly added files on any existing orders for this product prior to saving.
|
||||
if ( $this->is_type( 'variation' ) ) {
|
||||
do_action( 'woocommerce_process_product_file_download_paths', $this->get_parent_id(), $this->get_id(), $this->get_downloads() );
|
||||
} else {
|
||||
do_action( 'woocommerce_process_product_file_download_paths', $this->get_id(), 0, $this->get_downloads() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( in_array( 'stock_quantity', $updated_props ) ) {
|
||||
do_action( $this->is_type( 'variation' ) ? 'woocommerce_variation_set_stock' : 'woocommerce_product_set_stock' , $this );
|
||||
}
|
||||
|
||||
if ( in_array( 'stock_status', $updated_props ) ) {
|
||||
do_action( $this->is_type( 'variation' ) ? 'woocommerce_variation_set_stock_status' : 'woocommerce_product_set_stock_status' , $this->get_id(), $this->get_stock_status() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1629,7 +1650,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return bool
|
||||
*/
|
||||
public function is_purchasable() {
|
||||
return apply_filters( 'woocommerce_is_purchasable', $this->exists() && ( 'publish' === $this->get_status() || current_user_can( 'edit_post', $this->get_id() ) ) && '' !== $this->get_price(), $this );
|
||||
return apply_filters( 'woocommerce_is_purchasable', $this->exists() && $this->is_in_stock() && ( 'publish' === $this->get_status() || current_user_can( 'edit_post', $this->get_id() ) ) && '' !== $this->get_price(), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1742,7 +1763,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return bool
|
||||
*/
|
||||
public function is_on_backorder( $qty_in_cart = 0 ) {
|
||||
return $this->managing_stock() && $this->backorders_allowed() && ( $this->get_total_stock() - $qty_in_cart ) < 0 ? true : false;
|
||||
return $this->managing_stock() && $this->backorders_allowed() && ( $this->get_stock_quantity() - $qty_in_cart ) < 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1793,6 +1814,14 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Product permalink.
|
||||
* @return string
|
||||
*/
|
||||
public function get_permalink() {
|
||||
return get_permalink( $this->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the children IDs if applicable. Overridden by child classes.
|
||||
*
|
||||
|
@ -1841,7 +1870,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return string
|
||||
*/
|
||||
public function add_to_cart_url() {
|
||||
return apply_filters( 'woocommerce_product_add_to_cart_url', get_permalink( $this->get_id() ), $this );
|
||||
return apply_filters( 'woocommerce_product_add_to_cart_url', $this->get_permalink(), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1862,22 +1891,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
return apply_filters( 'woocommerce_product_add_to_cart_text', __( 'Read more', 'woocommerce' ), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the main product image ID.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_image_id() {
|
||||
if ( has_post_thumbnail( $this->get_id() ) ) {
|
||||
$image_id = get_post_thumbnail_id( $this->get_id() );
|
||||
} elseif ( ( $parent_id = wp_get_post_parent_id( $this->get_id() ) ) && has_post_thumbnail( $parent_id ) ) {
|
||||
$image_id = get_post_thumbnail_id( $parent_id );
|
||||
} else {
|
||||
$image_id = 0;
|
||||
}
|
||||
return $image_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main product image.
|
||||
*
|
||||
|
@ -1934,116 +1947,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
return $attribute_object->is_taxonomy() ? implode( ', ', wc_get_product_terms( $this->get_id(), $attribute_object->get_name(), array( 'fields' => 'names' ) ) ) : wc_implode_text_attributes( $attribute_object->get_options() );
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| @todo stock functions
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get total stock - This is the stock of parent and children combined.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_total_stock() {
|
||||
if ( empty( $this->total_stock ) ) {
|
||||
if ( sizeof( $this->get_children() ) > 0 ) {
|
||||
$this->total_stock = max( 0, $this->get_stock_quantity() );
|
||||
|
||||
foreach ( $this->get_children() as $child_id ) {
|
||||
if ( 'yes' === get_post_meta( $child_id, '_manage_stock', true ) ) {
|
||||
$stock = get_post_meta( $child_id, '_stock', true );
|
||||
$this->total_stock += max( 0, wc_stock_amount( $stock ) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->total_stock = $this->get_stock_quantity();
|
||||
}
|
||||
}
|
||||
return wc_stock_amount( $this->total_stock );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stock status needs changing.
|
||||
*/
|
||||
public function check_stock_status() {
|
||||
if ( ! $this->backorders_allowed() && $this->get_total_stock() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) {
|
||||
if ( 'outofstock' !== $this->stock_status ) {
|
||||
$this->set_stock_status( 'outofstock' );
|
||||
}
|
||||
} elseif ( $this->backorders_allowed() || $this->get_total_stock() > get_option( 'woocommerce_notify_no_stock_amount' ) ) {
|
||||
if ( 'instock' !== $this->stock_status ) {
|
||||
$this->set_stock_status( 'instock' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set stock level of the product. @todo '' stock if not managing it.
|
||||
*
|
||||
* Uses queries rather than update_post_meta so we can do this in one query (to avoid stock issues).
|
||||
* We cannot rely on the original loaded value in case another order was made since then.
|
||||
*
|
||||
* @param int $amount (default: null)
|
||||
* @param string $mode can be set, add, or subtract
|
||||
* @return int new stock level
|
||||
*/
|
||||
public function set_stock( $amount = null, $mode = 'set' ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! is_null( $amount ) && $this->managing_stock() ) {
|
||||
|
||||
// Ensure key exists
|
||||
add_post_meta( $this->get_id(), '_stock', 0, true );
|
||||
|
||||
// Update stock in DB directly
|
||||
switch ( $mode ) {
|
||||
case 'add' :
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = meta_value + %f WHERE post_id = %d AND meta_key='_stock'", $amount, $this->get_id() ) );
|
||||
break;
|
||||
case 'subtract' :
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = meta_value - %f WHERE post_id = %d AND meta_key='_stock'", $amount, $this->get_id() ) );
|
||||
break;
|
||||
default :
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %f WHERE post_id = %d AND meta_key='_stock'", $amount, $this->get_id() ) );
|
||||
break;
|
||||
}
|
||||
|
||||
// Clear caches
|
||||
wp_cache_delete( $this->get_id(), 'post_meta' );
|
||||
delete_transient( 'wc_low_stock_count' );
|
||||
delete_transient( 'wc_outofstock_count' );
|
||||
unset( $this->stock );
|
||||
|
||||
// Stock status
|
||||
$this->check_stock_status();
|
||||
|
||||
// Trigger action
|
||||
do_action( 'woocommerce_product_set_stock', $this );
|
||||
}
|
||||
|
||||
return $this->get_stock_quantity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce stock level of the product.
|
||||
*
|
||||
* @param int $amount Amount to reduce by. Default: 1
|
||||
* @return int new stock level
|
||||
*/
|
||||
public function reduce_stock( $amount = 1 ) {
|
||||
return $this->set_stock( $amount, 'subtract' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase stock level of the product.
|
||||
*
|
||||
* @param int $amount Amount to increase by. Default 1.
|
||||
* @return int new stock level
|
||||
*/
|
||||
public function increase_stock( $amount = 1 ) {
|
||||
return $this->set_stock( $amount, 'add' );
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -291,7 +291,7 @@ class WC_Admin_Post_Types {
|
|||
public function render_product_columns( $column ) {
|
||||
global $post, $the_product;
|
||||
|
||||
if ( empty( $the_product ) || $the_product->id != $post->ID ) {
|
||||
if ( empty( $the_product ) || $the_product->get_id() != $post->ID ) {
|
||||
$the_product = wc_get_product( $post );
|
||||
}
|
||||
|
||||
|
@ -406,9 +406,8 @@ class WC_Admin_Post_Types {
|
|||
$stock_html = '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
|
||||
}
|
||||
|
||||
// If the product has children, a single stock level would be misleading as some could be -ve and some +ve, some managed/some unmanaged etc so hide stock level in this case.
|
||||
if ( $the_product->managing_stock() && ! sizeof( $the_product->get_children() ) ) {
|
||||
$stock_html .= ' (' . $the_product->get_total_stock() . ')';
|
||||
if ( $the_product->managing_stock() ) {
|
||||
$stock_html .= ' (' . $the_product->get_stock_quantity() . ')';
|
||||
}
|
||||
|
||||
echo apply_filters( 'woocommerce_admin_stock_html', $stock_html, $the_product );
|
||||
|
@ -653,7 +652,7 @@ class WC_Admin_Post_Types {
|
|||
<td class="qty"><?php echo esc_html( $item->get_quantity() ); ?></td>
|
||||
<td class="name">
|
||||
<?php if ( $product ) : ?>
|
||||
<?php echo ( wc_product_sku_enabled() && $product->get_sku() ) ? $product->get_sku() . ' - ' : ''; ?><a href="<?php echo get_edit_post_link( $product->id ); ?>" title="<?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?>"><?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?></a>
|
||||
<?php echo ( wc_product_sku_enabled() && $product->get_sku() ) ? $product->get_sku() . ' - ' : ''; ?><a href="<?php echo get_edit_post_link( $product->get_id() ); ?>" title="<?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?>"><?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?></a>
|
||||
<?php else : ?>
|
||||
<?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?>
|
||||
<?php endif; ?>
|
||||
|
|
|
@ -40,7 +40,7 @@ class WC_Meta_Box_Order_Downloads {
|
|||
|
||||
if ( $download_permissions && sizeof( $download_permissions ) > 0 ) foreach ( $download_permissions as $download ) {
|
||||
|
||||
if ( ! $product || $product->id != $download->product_id ) {
|
||||
if ( ! $product || $product->get_id() != $download->product_id ) {
|
||||
$product = wc_get_product( absint( $download->product_id ) );
|
||||
$file_counter = 1;
|
||||
}
|
||||
|
|
|
@ -142,19 +142,17 @@ class WC_Meta_Box_Product_Data {
|
|||
* Prepare downloads for save.
|
||||
* @return array
|
||||
*/
|
||||
private static function prepare_downloads() {
|
||||
private static function prepare_downloads( $file_names, $file_urls ) {
|
||||
$downloads = array();
|
||||
|
||||
if ( isset( $_POST['_wc_file_urls'] ) ) {
|
||||
$file_names = isset( $_POST['_wc_file_names'] ) ? $_POST['_wc_file_names'] : array();
|
||||
$file_urls = isset( $_POST['_wc_file_urls'] ) ? wp_unslash( array_map( 'trim', $_POST['_wc_file_urls'] ) ) : array();
|
||||
if ( ! empty( $file_urls ) ) {
|
||||
$file_url_size = sizeof( $file_urls );
|
||||
|
||||
for ( $i = 0; $i < $file_url_size; $i ++ ) {
|
||||
if ( ! empty( $file_urls[ $i ] ) ) {
|
||||
$downloads[] = array(
|
||||
'name' => wc_clean( $file_names[ $i ] ),
|
||||
'file' => $file_urls[ $i ],
|
||||
'file' => wp_unslash( trim( $file_urls[ $i ] ) ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -219,6 +217,36 @@ class WC_Meta_Box_Product_Data {
|
|||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare attributes for a specific variation or defaults.
|
||||
* @param array $all_attributes
|
||||
* @param string $key_prefix
|
||||
* @param int $index
|
||||
* @return array
|
||||
*/
|
||||
private static function prepare_set_attributes( $all_attributes, $key_prefix = 'attribute_', $index = null ) {
|
||||
$attributes = array();
|
||||
|
||||
if ( $all_attributes ) {
|
||||
foreach ( $all_attributes as $attribute ) {
|
||||
if ( $attribute->get_variation() ) {
|
||||
$attribute_key = sanitize_title( $attribute->get_name() );
|
||||
|
||||
if ( ! is_null( $index ) ) {
|
||||
$value = isset( $_POST[ $key_prefix . $attribute_key ][ $index ] ) ? stripslashes( $_POST[ $key_prefix . $attribute_key ][ $index ] ) : '';
|
||||
} else {
|
||||
$value = isset( $_POST[ $key_prefix . $attribute_key ] ) ? stripslashes( $_POST[ $key_prefix . $attribute_key ] ) : '';
|
||||
}
|
||||
|
||||
$value = $attribute->is_taxonomy() ? sanitize_title( $value ) : wc_clean( $value ); // Don't use wc_clean as it destroys sanitized characters in terms.
|
||||
$attributes[ $attribute_key ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data.
|
||||
*/
|
||||
|
@ -231,38 +259,40 @@ class WC_Meta_Box_Product_Data {
|
|||
$classname = 'WC_Product_Simple';
|
||||
}
|
||||
|
||||
$product = new $classname( $post_id );
|
||||
$errors = $product->set_props( array(
|
||||
'sku' => isset( $_POST['_sku'] ) ? wc_clean( $_POST['_sku'] ) : null,
|
||||
'purchase_note' => wp_kses_post( stripslashes( $_POST['_purchase_note'] ) ),
|
||||
'downloadable' => isset( $_POST['_downloadable'] ),
|
||||
'virtual' => isset( $_POST['_virtual'] ),
|
||||
'tax_status' => wc_clean( $_POST['_tax_status'] ),
|
||||
'tax_class' => wc_clean( $_POST['_tax_class'] ),
|
||||
'weight' => wc_clean( $_POST['_weight'] ),
|
||||
'length' => wc_clean( $_POST['_length'] ),
|
||||
'width' => wc_clean( $_POST['_width'] ),
|
||||
'height' => wc_clean( $_POST['_height'] ),
|
||||
'shipping_class_id' => absint( $_POST['product_shipping_class'] ),
|
||||
'sold_individually' => ! empty( $_POST['_sold_individually'] ),
|
||||
'upsell_ids' => array_map( 'intval', explode( ',', $_POST['upsell_ids'] ) ),
|
||||
'crosssell_ids' => array_map( 'intval', explode( ',', $_POST['crosssell_ids'] ) ),
|
||||
'regular_price' => wc_clean( $_POST['_regular_price'] ),
|
||||
'sale_price' => wc_clean( $_POST['_sale_price'] ),
|
||||
'date_on_sale_from' => wc_clean( $_POST['_sale_price_dates_from'] ),
|
||||
'date_on_sale_to' => wc_clean( $_POST['_sale_price_dates_to'] ),
|
||||
'manage_stock' => ! empty( $_POST['_manage_stock'] ),
|
||||
'backorders' => wc_clean( $_POST['_backorders'] ),
|
||||
'stock_status' => wc_clean( $_POST['_stock_status'] ),
|
||||
'stock_quantity' => wc_stock_amount( $_POST['_stock'] ),
|
||||
'attributes' => self::prepare_attributes(),
|
||||
'download_limit' => '' === $_POST['_download_limit'] ? '' : absint( $_POST['_download_limit'] ),
|
||||
'download_expiry' => '' === $_POST['_download_expiry'] ? '' : absint( $_POST['_download_expiry'] ),
|
||||
'downloads' => self::prepare_downloads(),
|
||||
'product_url' => esc_url_raw( $_POST['_product_url'] ),
|
||||
'button_text' => wc_clean( $_POST['_button_text'] ),
|
||||
'children' => 'grouped' === $product_type ? self::prepare_children() : null,
|
||||
'reviews_allowed' => ! empty( $_POST['_reviews_allowed'] ),
|
||||
$product = new $classname( $post_id );
|
||||
$attributes = self::prepare_attributes();
|
||||
$errors = $product->set_props( array(
|
||||
'sku' => isset( $_POST['_sku'] ) ? wc_clean( $_POST['_sku'] ) : null,
|
||||
'purchase_note' => wp_kses_post( stripslashes( $_POST['_purchase_note'] ) ),
|
||||
'downloadable' => isset( $_POST['_downloadable'] ),
|
||||
'virtual' => isset( $_POST['_virtual'] ),
|
||||
'tax_status' => wc_clean( $_POST['_tax_status'] ),
|
||||
'tax_class' => wc_clean( $_POST['_tax_class'] ),
|
||||
'weight' => wc_clean( $_POST['_weight'] ),
|
||||
'length' => wc_clean( $_POST['_length'] ),
|
||||
'width' => wc_clean( $_POST['_width'] ),
|
||||
'height' => wc_clean( $_POST['_height'] ),
|
||||
'shipping_class_id' => absint( $_POST['product_shipping_class'] ),
|
||||
'sold_individually' => ! empty( $_POST['_sold_individually'] ),
|
||||
'upsell_ids' => array_map( 'intval', explode( ',', $_POST['upsell_ids'] ) ),
|
||||
'crosssell_ids' => array_map( 'intval', explode( ',', $_POST['crosssell_ids'] ) ),
|
||||
'regular_price' => wc_clean( $_POST['_regular_price'] ),
|
||||
'sale_price' => wc_clean( $_POST['_sale_price'] ),
|
||||
'date_on_sale_from' => wc_clean( $_POST['_sale_price_dates_from'] ),
|
||||
'date_on_sale_to' => wc_clean( $_POST['_sale_price_dates_to'] ),
|
||||
'manage_stock' => ! empty( $_POST['_manage_stock'] ),
|
||||
'backorders' => wc_clean( $_POST['_backorders'] ),
|
||||
'stock_status' => wc_clean( $_POST['_stock_status'] ),
|
||||
'stock_quantity' => wc_stock_amount( $_POST['_stock'] ),
|
||||
'download_limit' => '' === $_POST['_download_limit'] ? '' : absint( $_POST['_download_limit'] ),
|
||||
'download_expiry' => '' === $_POST['_download_expiry'] ? '' : absint( $_POST['_download_expiry'] ),
|
||||
'downloads' => self::prepare_downloads( isset( $_POST['_wc_file_names'] ) ? $_POST['_wc_file_names'] : array(), isset( $_POST['_wc_file_urls'] ) ? $_POST['_wc_file_urls'] : array() ),
|
||||
'product_url' => esc_url_raw( $_POST['_product_url'] ),
|
||||
'button_text' => wc_clean( $_POST['_button_text'] ),
|
||||
'children' => 'grouped' === $product_type ? self::prepare_children() : null,
|
||||
'reviews_allowed' => ! empty( $_POST['_reviews_allowed'] ),
|
||||
'attributes' => $attributes,
|
||||
'default_attributes' => self::prepare_set_attributes( $attributes, 'default_attribute_' ),
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $errors ) ) {
|
||||
|
@ -281,287 +311,54 @@ class WC_Meta_Box_Product_Data {
|
|||
* @param WP_Post $post
|
||||
*/
|
||||
public static function save_variations( $post_id, $post ) {
|
||||
global $wpdb;
|
||||
|
||||
$attributes = (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) );
|
||||
|
||||
if ( isset( $_POST['variable_sku'] ) ) {
|
||||
$variable_post_id = $_POST['variable_post_id'];
|
||||
$variable_sku = $_POST['variable_sku'];
|
||||
$variable_regular_price = $_POST['variable_regular_price'];
|
||||
$variable_sale_price = $_POST['variable_sale_price'];
|
||||
$upload_image_id = $_POST['upload_image_id'];
|
||||
$variable_download_limit = $_POST['variable_download_limit'];
|
||||
$variable_download_expiry = $_POST['variable_download_expiry'];
|
||||
$variable_shipping_class = $_POST['variable_shipping_class'];
|
||||
$variable_tax_class = isset( $_POST['variable_tax_class'] ) ? $_POST['variable_tax_class'] : array();
|
||||
$variable_menu_order = $_POST['variation_menu_order'];
|
||||
$variable_sale_price_dates_from = $_POST['variable_sale_price_dates_from'];
|
||||
$variable_sale_price_dates_to = $_POST['variable_sale_price_dates_to'];
|
||||
|
||||
$variable_weight = isset( $_POST['variable_weight'] ) ? $_POST['variable_weight'] : array();
|
||||
$variable_length = isset( $_POST['variable_length'] ) ? $_POST['variable_length'] : array();
|
||||
$variable_width = isset( $_POST['variable_width'] ) ? $_POST['variable_width'] : array();
|
||||
$variable_height = isset( $_POST['variable_height'] ) ? $_POST['variable_height'] : array();
|
||||
$variable_enabled = isset( $_POST['variable_enabled'] ) ? $_POST['variable_enabled'] : array();
|
||||
$variable_is_virtual = isset( $_POST['variable_is_virtual'] ) ? $_POST['variable_is_virtual'] : array();
|
||||
$variable_is_downloadable = isset( $_POST['variable_is_downloadable'] ) ? $_POST['variable_is_downloadable'] : array();
|
||||
|
||||
$variable_manage_stock = isset( $_POST['variable_manage_stock'] ) ? $_POST['variable_manage_stock'] : array();
|
||||
$variable_stock = isset( $_POST['variable_stock'] ) ? $_POST['variable_stock'] : array();
|
||||
$variable_backorders = isset( $_POST['variable_backorders'] ) ? $_POST['variable_backorders'] : array();
|
||||
$variable_stock_status = isset( $_POST['variable_stock_status'] ) ? $_POST['variable_stock_status'] : array();
|
||||
|
||||
$variable_description = isset( $_POST['variable_description'] ) ? $_POST['variable_description'] : array();
|
||||
|
||||
if ( isset( $_POST['variable_post_id'] ) ) {
|
||||
$parent = wc_get_product( $post_id );
|
||||
$max_loop = max( array_keys( $_POST['variable_post_id'] ) );
|
||||
|
||||
for ( $i = 0; $i <= $max_loop; $i ++ ) {
|
||||
|
||||
if ( ! isset( $variable_post_id[ $i ] ) ) {
|
||||
if ( ! isset( $_POST['variable_post_id'][ $i ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$variation_id = absint( $variable_post_id[ $i ] );
|
||||
|
||||
// Checkboxes
|
||||
$is_virtual = isset( $variable_is_virtual[ $i ] ) ? 'yes' : 'no';
|
||||
$is_downloadable = isset( $variable_is_downloadable[ $i ] ) ? 'yes' : 'no';
|
||||
$post_status = isset( $variable_enabled[ $i ] ) ? 'publish' : 'private';
|
||||
$manage_stock = isset( $variable_manage_stock[ $i ] ) ? 'yes' : 'no';
|
||||
|
||||
// Generate a useful post title
|
||||
$variation_post_title = sprintf( __( 'Variation #%1$s of %2$s', 'woocommerce' ), absint( $variation_id ), esc_html( get_the_title( $post_id ) ) );
|
||||
|
||||
// Update or Add post
|
||||
if ( ! $variation_id ) {
|
||||
|
||||
$variation = array(
|
||||
'post_title' => $variation_post_title,
|
||||
'post_content' => '',
|
||||
'post_status' => $post_status,
|
||||
'post_author' => get_current_user_id(),
|
||||
'post_parent' => $post_id,
|
||||
'post_type' => 'product_variation',
|
||||
'menu_order' => $variable_menu_order[ $i ],
|
||||
);
|
||||
|
||||
$variation_id = wp_insert_post( $variation );
|
||||
|
||||
do_action( 'woocommerce_create_product_variation', $variation_id );
|
||||
|
||||
} else {
|
||||
|
||||
$modified_date = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
|
||||
|
||||
$wpdb->update( $wpdb->posts, array(
|
||||
'post_status' => $post_status,
|
||||
'post_title' => $variation_post_title,
|
||||
'menu_order' => $variable_menu_order[ $i ],
|
||||
'post_modified' => $modified_date,
|
||||
'post_modified_gmt' => get_gmt_from_date( $modified_date ),
|
||||
), array( 'ID' => $variation_id ) );
|
||||
|
||||
clean_post_cache( $variation_id );
|
||||
|
||||
do_action( 'woocommerce_update_product_variation', $variation_id );
|
||||
$variation_id = absint( $_POST['variable_post_id'][ $i ] );
|
||||
$variation = new WC_Product_Variation( $variation_id );
|
||||
$errors = $variation->set_props( array(
|
||||
'status' => isset( $_POST['variable_enabled'][ $i ] ) ? 'publish' : 'private',
|
||||
'menu_order' => wc_clean( $_POST['variation_menu_order'][ $i ] ),
|
||||
'regular_price' => wc_clean( $_POST['variable_regular_price'][ $i ] ),
|
||||
'sale_price' => wc_clean( $_POST['variable_sale_price'][ $i ] ),
|
||||
'virtual' => isset( $_POST['variable_is_virtual'][ $i ] ),
|
||||
'downloadable' => isset( $_POST['variable_is_downloadable'][ $i ] ),
|
||||
'date_on_sale_from' => wc_clean( $_POST['variable_sale_price_dates_from'][ $i ] ),
|
||||
'date_on_sale_to' => wc_clean( $_POST['variable_sale_price_dates_to'][ $i ] ),
|
||||
'description' => wp_kses_post( wc_sanitize_textarea( $_POST['variable_description'][ $i ] ) ),
|
||||
'download_limit' => wc_clean( $_POST['variable_download_limit'][ $i ] ),
|
||||
'download_expiry' => wc_clean( $_POST['variable_download_expiry'][ $i ] ),
|
||||
'downloads' => self::prepare_downloads( isset( $_POST['_wc_variation_file_names'][ $variation_id ] ) ? $_POST['_wc_variation_file_names'][ $variation_id ] : array(), isset( $_POST['_wc_variation_file_urls'][ $variation_id ] ) ? $_POST['_wc_variation_file_urls'][ $variation_id ] : array() ),
|
||||
'manage_stock' => isset( $_POST['variable_manage_stock'][ $i ] ),
|
||||
'stock_quantity' => wc_clean( $_POST['variable_stock'][ $i ] ),
|
||||
'backorders' => wc_clean( $_POST['variable_backorders'][ $i ] ),
|
||||
'stock_status' => wc_clean( $_POST['variable_stock_status'][ $i ] ),
|
||||
'image_id' => wc_clean( $_POST['upload_image_id'][ $i ] ),
|
||||
'attributes' => self::prepare_set_attributes( $parent->get_attributes(), 'attribute_', $i ),
|
||||
'sku' => isset( $_POST['variable_sku'][ $i ] ) ? wc_clean( $_POST['variable_sku'][ $i ] ) : '',
|
||||
'weight' => isset( $_POST['variable_weight'][ $i ] ) ? wc_clean( $_POST['variable_weight'][ $i ] ) : '',
|
||||
'length' => isset( $_POST['variable_length'][ $i ] ) ? wc_clean( $_POST['variable_length'][ $i ] ) : '',
|
||||
'width' => isset( $_POST['variable_width'][ $i ] ) ? wc_clean( $_POST['variable_width'][ $i ] ) : '',
|
||||
'height' => isset( $_POST['variable_height'][ $i ] ) ? wc_clean( $_POST['variable_height'][ $i ] ) : '',
|
||||
'shipping_class_id' => wc_clean( $_POST['variable_shipping_class'][ $i ] ),
|
||||
'tax_class' => wc_clean( $_POST['variable_tax_class'][ $i ] ),
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $errors ) ) {
|
||||
WC_Admin_Meta_Boxes::add_error( $errors->get_error_message() );
|
||||
}
|
||||
|
||||
// Only continue if we have a variation ID
|
||||
if ( ! $variation_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Unique SKU
|
||||
$sku = get_post_meta( $variation_id, '_sku', true );
|
||||
$new_sku = wc_clean( $variable_sku[ $i ] );
|
||||
|
||||
if ( '' == $new_sku ) {
|
||||
update_post_meta( $variation_id, '_sku', '' );
|
||||
} elseif ( $new_sku !== $sku ) {
|
||||
if ( ! empty( $new_sku ) ) {
|
||||
$unique_sku = wc_product_has_unique_sku( $variation_id, $new_sku );
|
||||
|
||||
if ( ! $unique_sku ) {
|
||||
WC_Admin_Meta_Boxes::add_error( sprintf( __( '#%s – Variation SKU must be unique.', 'woocommerce' ), $variation_id ) );
|
||||
} else {
|
||||
update_post_meta( $variation_id, '_sku', $new_sku );
|
||||
}
|
||||
} else {
|
||||
update_post_meta( $variation_id, '_sku', '' );
|
||||
}
|
||||
}
|
||||
|
||||
// Update post meta
|
||||
update_post_meta( $variation_id, '_thumbnail_id', absint( $upload_image_id[ $i ] ) );
|
||||
update_post_meta( $variation_id, '_virtual', wc_clean( $is_virtual ) );
|
||||
update_post_meta( $variation_id, '_downloadable', wc_clean( $is_downloadable ) );
|
||||
|
||||
if ( isset( $variable_weight[ $i ] ) ) {
|
||||
update_post_meta( $variation_id, '_weight', ( '' === $variable_weight[ $i ] ) ? '' : wc_format_decimal( $variable_weight[ $i ] ) );
|
||||
}
|
||||
|
||||
if ( isset( $variable_length[ $i ] ) ) {
|
||||
update_post_meta( $variation_id, '_length', ( '' === $variable_length[ $i ] ) ? '' : wc_format_decimal( $variable_length[ $i ] ) );
|
||||
}
|
||||
|
||||
if ( isset( $variable_width[ $i ] ) ) {
|
||||
update_post_meta( $variation_id, '_width', ( '' === $variable_width[ $i ] ) ? '' : wc_format_decimal( $variable_width[ $i ] ) );
|
||||
}
|
||||
|
||||
if ( isset( $variable_height[ $i ] ) ) {
|
||||
update_post_meta( $variation_id, '_height', ( '' === $variable_height[ $i ] ) ? '' : wc_format_decimal( $variable_height[ $i ] ) );
|
||||
}
|
||||
|
||||
// Stock handling
|
||||
update_post_meta( $variation_id, '_manage_stock', $manage_stock );
|
||||
|
||||
if ( 'yes' === $manage_stock ) {
|
||||
update_post_meta( $variation_id, '_backorders', wc_clean( $variable_backorders[ $i ] ) );
|
||||
wc_update_product_stock( $variation_id, wc_stock_amount( $variable_stock[ $i ] ) );
|
||||
} else {
|
||||
delete_post_meta( $variation_id, '_backorders' );
|
||||
wc_update_product_stock( $variation_id, '' );
|
||||
}
|
||||
|
||||
// Only update stock status to user setting if changed by the user, but do so before looking at stock levels at variation level
|
||||
if ( ! empty( $variable_stock_status[ $i ] ) ) {
|
||||
wc_update_product_stock_status( $variation_id, $variable_stock_status[ $i ] );
|
||||
}
|
||||
|
||||
// Price handling
|
||||
_wc_save_product_price( $variation_id, $variable_regular_price[ $i ], $variable_sale_price[ $i ], $variable_sale_price_dates_from[ $i ], $variable_sale_price_dates_to[ $i ] );
|
||||
|
||||
if ( isset( $variable_tax_class[ $i ] ) && 'parent' !== $variable_tax_class[ $i ] ) {
|
||||
update_post_meta( $variation_id, '_tax_class', wc_clean( $variable_tax_class[ $i ] ) );
|
||||
} else {
|
||||
delete_post_meta( $variation_id, '_tax_class' );
|
||||
}
|
||||
|
||||
if ( 'yes' == $is_downloadable ) {
|
||||
update_post_meta( $variation_id, '_download_limit', wc_clean( $variable_download_limit[ $i ] ) );
|
||||
update_post_meta( $variation_id, '_download_expiry', wc_clean( $variable_download_expiry[ $i ] ) );
|
||||
|
||||
$files = array();
|
||||
$file_names = isset( $_POST['_wc_variation_file_names'][ $variation_id ] ) ? array_map( 'wc_clean', $_POST['_wc_variation_file_names'][ $variation_id ] ) : array();
|
||||
$file_urls = isset( $_POST['_wc_variation_file_urls'][ $variation_id ] ) ? array_map( 'wc_clean', $_POST['_wc_variation_file_urls'][ $variation_id ] ) : array();
|
||||
$file_url_size = sizeof( $file_urls );
|
||||
$allowed_file_types = get_allowed_mime_types();
|
||||
|
||||
for ( $ii = 0; $ii < $file_url_size; $ii ++ ) {
|
||||
if ( ! empty( $file_urls[ $ii ] ) ) {
|
||||
// Find type and file URL
|
||||
if ( 0 === strpos( $file_urls[ $ii ], 'http' ) ) {
|
||||
$file_is = 'absolute';
|
||||
$file_url = esc_url_raw( $file_urls[ $ii ] );
|
||||
} elseif ( '[' === substr( $file_urls[ $ii ], 0, 1 ) && ']' === substr( $file_urls[ $ii ], -1 ) ) {
|
||||
$file_is = 'shortcode';
|
||||
$file_url = wc_clean( $file_urls[ $ii ] );
|
||||
} else {
|
||||
$file_is = 'relative';
|
||||
$file_url = wc_clean( $file_urls[ $ii ] );
|
||||
}
|
||||
|
||||
$file_name = wc_clean( $file_names[ $ii ] );
|
||||
$file_hash = md5( $file_url );
|
||||
|
||||
// Validate the file extension
|
||||
if ( in_array( $file_is, array( 'absolute', 'relative' ) ) ) {
|
||||
$file_type = wp_check_filetype( strtok( $file_url, '?' ), $allowed_file_types );
|
||||
$parsed_url = parse_url( $file_url, PHP_URL_PATH );
|
||||
$extension = pathinfo( $parsed_url, PATHINFO_EXTENSION );
|
||||
|
||||
if ( ! empty( $extension ) && ! in_array( $file_type['type'], $allowed_file_types ) ) {
|
||||
WC_Admin_Meta_Boxes::add_error( sprintf( __( '#%1$s – The downloadable file %2$s cannot be used as it does not have an allowed file type. Allowed types include: %3$s', 'woocommerce' ), $variation_id, '<code>' . basename( $file_url ) . '</code>', '<code>' . implode( ', ', array_keys( $allowed_file_types ) ) . '</code>' ) );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the file exists
|
||||
if ( 'relative' === $file_is && ! apply_filters( 'woocommerce_downloadable_file_exists', file_exists( $file_url ), $file_url ) ) {
|
||||
WC_Admin_Meta_Boxes::add_error( sprintf( __( '#%1$s – The downloadable file %2$s cannot be used as it does not exist on the server.', 'woocommerce' ), $variation_id, '<code>' . $file_url . '</code>' ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
$files[ $file_hash ] = array(
|
||||
'name' => $file_name,
|
||||
'file' => $file_url,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// grant permission to any newly added files on any existing orders for this product prior to saving
|
||||
do_action( 'woocommerce_process_product_file_download_paths', $post_id, $variation_id, $files );
|
||||
|
||||
update_post_meta( $variation_id, '_downloadable_files', $files );
|
||||
} else {
|
||||
update_post_meta( $variation_id, '_download_limit', '' );
|
||||
update_post_meta( $variation_id, '_download_expiry', '' );
|
||||
update_post_meta( $variation_id, '_downloadable_files', '' );
|
||||
}
|
||||
|
||||
update_post_meta( $variation_id, '_variation_description', wp_kses_post( $variable_description[ $i ] ) );
|
||||
|
||||
// Save shipping class
|
||||
$variable_shipping_class[ $i ] = ! empty( $variable_shipping_class[ $i ] ) ? (int) $variable_shipping_class[ $i ] : '';
|
||||
wp_set_object_terms( $variation_id, $variable_shipping_class[ $i ], 'product_shipping_class' );
|
||||
|
||||
// Update Attributes
|
||||
$updated_attribute_keys = array();
|
||||
foreach ( $attributes as $attribute ) {
|
||||
if ( $attribute['is_variation'] ) {
|
||||
$attribute_key = 'attribute_' . sanitize_title( $attribute['name'] );
|
||||
$updated_attribute_keys[] = $attribute_key;
|
||||
|
||||
if ( $attribute['is_taxonomy'] ) {
|
||||
// Don't use wc_clean as it destroys sanitized characters
|
||||
$value = isset( $_POST[ $attribute_key ][ $i ] ) ? sanitize_title( stripslashes( $_POST[ $attribute_key ][ $i ] ) ) : '';
|
||||
} else {
|
||||
$value = isset( $_POST[ $attribute_key ][ $i ] ) ? wc_clean( stripslashes( $_POST[ $attribute_key ][ $i ] ) ) : '';
|
||||
}
|
||||
|
||||
update_post_meta( $variation_id, $attribute_key, $value );
|
||||
}
|
||||
}
|
||||
|
||||
// Remove old taxonomies attributes so data is kept up to date - first get attribute key names
|
||||
$delete_attribute_keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->postmeta} WHERE meta_key LIKE 'attribute_%%' AND meta_key NOT IN ( '" . implode( "','", $updated_attribute_keys ) . "' ) AND post_id = %d;", $variation_id ) );
|
||||
|
||||
foreach ( $delete_attribute_keys as $key ) {
|
||||
delete_post_meta( $variation_id, $key );
|
||||
}
|
||||
$variation->save();
|
||||
|
||||
do_action( 'woocommerce_save_product_variation', $variation_id, $i );
|
||||
}
|
||||
}
|
||||
|
||||
// Update parent if variable so price sorting works and stays in sync with the cheapest child
|
||||
WC_Product_Variable::sync( $post_id );
|
||||
|
||||
// Update default attribute options setting
|
||||
$default_attributes = array();
|
||||
|
||||
foreach ( $attributes as $attribute ) {
|
||||
|
||||
if ( $attribute['is_variation'] ) {
|
||||
$value = '';
|
||||
|
||||
if ( isset( $_POST[ 'default_attribute_' . sanitize_title( $attribute['name'] ) ] ) ) {
|
||||
if ( $attribute['is_taxonomy'] ) {
|
||||
// Don't use wc_clean as it destroys sanitized characters
|
||||
$value = sanitize_title( trim( stripslashes( $_POST[ 'default_attribute_' . sanitize_title( $attribute['name'] ) ] ) ) );
|
||||
} else {
|
||||
$value = wc_clean( trim( stripslashes( $_POST[ 'default_attribute_' . sanitize_title( $attribute['name'] ) ] ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $value ) {
|
||||
$default_attributes[ sanitize_title( $attribute['name'] ) ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $post_id, '_default_attributes', $default_attributes );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<button type="button" data-permission_id="<?php echo absint( $download->permission_id ); ?>" rel="<?php echo absint( $download->product_id ) . ',' . esc_attr( $download->download_id ); ?>" class="revoke_access button"><?php _e( 'Revoke Access', 'woocommerce' ); ?></button>
|
||||
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'woocommerce' ); ?>"></div>
|
||||
<strong>
|
||||
<?php echo '#' . absint( $product->id ) . ' — ' . apply_filters( 'woocommerce_admin_download_permissions_title', $product->get_title(), $download->product_id, $download->order_id, $download->order_key, $download->download_id ) . ' — ' . esc_html( $file_count ) . ': ' . wc_get_filename_from_url( $product->get_file_download_path( $download->download_id ) ) . ' — ' . sprintf( _n( 'Downloaded %s time', 'Downloaded %s times', absint( $download->download_count ), 'woocommerce' ), absint( $download->download_count ) ); ?>
|
||||
<?php echo '#' . absint( $product->get_id() ) . ' — ' . apply_filters( 'woocommerce_admin_download_permissions_title', $product->get_title(), $download->product_id, $download->order_id, $download->order_key, $download->download_id ) . ' — ' . esc_html( $file_count ) . ': ' . wc_get_filename_from_url( $product->get_file_download_path( $download->download_id ) ) . ' — ' . sprintf( _n( 'Downloaded %s time', 'Downloaded %s times', absint( $download->download_count ), 'woocommerce' ), absint( $download->download_count ) ); ?>
|
||||
</strong>
|
||||
</h3>
|
||||
<table cellpadding="0" cellspacing="0" class="wc-metabox-content">
|
||||
|
|
|
@ -15,17 +15,9 @@ $line_items_fee = $order->get_items( 'fee' );
|
|||
$line_items_shipping = $order->get_items( 'shipping' );
|
||||
|
||||
if ( wc_tax_enabled() ) {
|
||||
$order_taxes = $order->get_taxes();
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
$classes_options = array();
|
||||
$classes_options[''] = __( 'Standard', 'woocommerce' );
|
||||
|
||||
if ( ! empty( $tax_classes ) ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$classes_options[ sanitize_title( $class ) ] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
$order_taxes = $order->get_taxes();
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
$classes_options = wc_get_product_tax_class_options();
|
||||
$show_tax_columns = sizeof( $order_taxes ) === 1;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -136,21 +136,11 @@
|
|||
'description' => __( 'Define whether or not the entire product is taxable, or just the cost of shipping it.', 'woocommerce' ),
|
||||
) );
|
||||
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
$classes_options = array();
|
||||
$classes_options[''] = __( 'Standard', 'woocommerce' );
|
||||
|
||||
if ( ! empty( $tax_classes ) ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
|
||||
}
|
||||
}
|
||||
|
||||
woocommerce_wp_select( array(
|
||||
'id' => '_tax_class',
|
||||
'value' => $product_object->get_tax_class(),
|
||||
'label' => __( 'Tax class', 'woocommerce' ),
|
||||
'options' => $classes_options,
|
||||
'options' => wc_get_product_tax_class_options(),
|
||||
'desc_tip' => 'true',
|
||||
'description' => __( 'Choose a tax class for this product. Tax classes are used to apply different tax rates specific to certain types of product.', 'woocommerce' ),
|
||||
) );
|
||||
|
|
|
@ -45,11 +45,7 @@
|
|||
'id' => '_backorders',
|
||||
'value' => $product_object->get_backorders(),
|
||||
'label' => __( 'Allow backorders?', 'woocommerce' ),
|
||||
'options' => array(
|
||||
'no' => __( 'Do not allow', 'woocommerce' ),
|
||||
'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
|
||||
'yes' => __( 'Allow', 'woocommerce' ),
|
||||
),
|
||||
'options' => wc_get_product_backorder_options(),
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce' ),
|
||||
) );
|
||||
|
@ -64,10 +60,7 @@
|
|||
'value' => $product_object->get_stock_status(),
|
||||
'wrapper_class' => 'hide_if_variable hide_if_external',
|
||||
'label' => __( 'Stock status', 'woocommerce' ),
|
||||
'options' => array(
|
||||
'instock' => __( 'In stock', 'woocommerce' ),
|
||||
'outofstock' => __( 'Out of stock', 'woocommerce' ),
|
||||
),
|
||||
'options' => wc_get_product_stock_status_options(),
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
|
||||
) );
|
||||
|
@ -83,7 +76,7 @@
|
|||
'value' => $product_object->get_sold_individually() ? 'yes' : 'no',
|
||||
'wrapper_class' => 'show_if_simple show_if_variable',
|
||||
'label' => __( 'Sold individually', 'woocommerce' ),
|
||||
'description' => __( 'Enable this to only allow one of this item to be bought in a single order', 'woocommerce' )
|
||||
'description' => __( 'Enable this to only allow one of this item to be bought in a single order', 'woocommerce' ),
|
||||
) );
|
||||
|
||||
do_action( 'woocommerce_product_options_sold_individually' );
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* Outputs a variation
|
||||
* Outputs a variation for editing.
|
||||
*
|
||||
* @var int $variation_id
|
||||
* @var WP_POST $variation
|
||||
* @var array $variation_data array of variation data
|
||||
* @var WP_Product_Variation $variation_object
|
||||
* @var array $variation_data array of variation data @deprecated.
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
extract( $variation_data );
|
||||
?>
|
||||
<div class="woocommerce_variation wc-metabox closed">
|
||||
<h3>
|
||||
|
@ -19,95 +18,111 @@ extract( $variation_data );
|
|||
<div class="tips sort" data-tip="<?php esc_attr_e( 'Drag and drop, or click to set admin variation order', 'woocommerce' ); ?>"></div>
|
||||
<strong>#<?php echo esc_html( $variation_id ); ?> </strong>
|
||||
<?php
|
||||
foreach ( $parent_data['attributes'] as $attribute ) {
|
||||
$attribute_values = $variation_object->get_attributes();
|
||||
|
||||
// Only deal with attributes that are variations
|
||||
if ( ! $attribute['is_variation'] || 'false' === $attribute['is_variation'] ) {
|
||||
foreach ( $product_object->get_attributes() as $attribute ) {
|
||||
if ( ! $attribute->get_variation() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get current value for variation (if set)
|
||||
$variation_selected_value = isset( $variation_data[ 'attribute_' . sanitize_title( $attribute['name'] ) ] ) ? $variation_data[ 'attribute_' . sanitize_title( $attribute['name'] ) ] : '';
|
||||
|
||||
// Name will be something like attribute_pa_color
|
||||
echo '<select name="attribute_' . sanitize_title( $attribute['name'] ) . '[' . $loop . ']"><option value="">' . __( 'Any', 'woocommerce' ) . ' ' . esc_html( wc_attribute_label( $attribute['name'] ) ) . '…</option>';
|
||||
|
||||
// Get terms for attribute taxonomy or value if its a custom attribute
|
||||
if ( $attribute['is_taxonomy'] ) {
|
||||
|
||||
$post_terms = wp_get_post_terms( $parent_data['id'], $attribute['name'] );
|
||||
|
||||
foreach ( $post_terms as $term ) {
|
||||
echo '<option ' . selected( $variation_selected_value, $term->slug, false ) . ' value="' . esc_attr( $term->slug ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>';
|
||||
}
|
||||
} else {
|
||||
|
||||
$options = wc_get_text_attributes( $attribute['value'] );
|
||||
|
||||
foreach ( $options as $option ) {
|
||||
$selected = sanitize_title( $variation_selected_value ) === $variation_selected_value ? selected( $variation_selected_value, sanitize_title( $option ), false ) : selected( $variation_selected_value, $option, false );
|
||||
echo '<option ' . $selected . ' value="' . esc_attr( $option ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</select>';
|
||||
$selected_value = isset( $attribute_values[ 'attribute_' . sanitize_title( $attribute->get_name() ) ] ) ? $attribute_values[ 'attribute_' . sanitize_title( $attribute->get_name() ) ] : '';
|
||||
?>
|
||||
<select name="attribute_<?php echo sanitize_title( $attribute->get_name() ) . "[{$loop}]"; ?>">
|
||||
<option value=""><?php echo esc_html( __( 'Any', 'woocommerce' ) . ' ' . wc_attribute_label( $attribute->get_name() ) ); ?>…</option>
|
||||
<?php if ( $attribute->is_taxonomy() ) : ?>
|
||||
<?php foreach ( $attribute->get_terms() as $option ) : ?>
|
||||
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name ) ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<?php foreach ( $attribute->get_options() as $option ) : ?>
|
||||
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="variable_post_id[<?php echo $loop; ?>]" value="<?php echo esc_attr( $variation_id ); ?>" />
|
||||
<input type="hidden" class="variation_menu_order" name="variation_menu_order[<?php echo $loop; ?>]" value="<?php echo isset( $menu_order ) ? absint( $menu_order ) : 0; ?>" />
|
||||
<input type="hidden" class="variation_menu_order" name="variation_menu_order[<?php echo $loop; ?>]" value="<?php echo esc_attr( $variation_object->get_menu_order() ); ?>" />
|
||||
</h3>
|
||||
<div class="woocommerce_variable_attributes wc-metabox-content" style="display: none;">
|
||||
<div class="data">
|
||||
<p class="form-row form-row-first upload_image">
|
||||
<a href="#" class="upload_image_button tips <?php echo ( $_thumbnail_id > 0 ) ? 'remove' : ''; ?>" data-tip="<?php echo ( $_thumbnail_id > 0 ) ? __( 'Remove this image', 'woocommerce' ) : __( 'Upload an image', 'woocommerce' ); ?>" rel="<?php echo esc_attr( $variation_id ); ?>"><img src="<?php echo ( ! empty( $image ) ) ? esc_attr( $image ) : esc_attr( wc_placeholder_img_src() ); ?>" /><input type="hidden" name="upload_image_id[<?php echo $loop; ?>]" class="upload_image_id" value="<?php echo esc_attr( $_thumbnail_id ); ?>" /></a>
|
||||
<a href="#" class="upload_image_button tips <?php echo $variation_object->get_image_id() ? 'remove' : ''; ?>" data-tip="<?php echo $variation_object->get_image_id() ? __( 'Remove this image', 'woocommerce' ) : __( 'Upload an image', 'woocommerce' ); ?>" rel="<?php echo esc_attr( $variation_id ); ?>">
|
||||
<img src="<?php echo $variation_object->get_image_id() ? esc_url( wp_get_attachment_thumb_url( $variation_object->get_image_id() ) ) : esc_url( wc_placeholder_img_src() ); ?>" /><input type="hidden" name="upload_image_id[<?php echo $loop; ?>]" class="upload_image_id" value="<?php echo esc_attr( $variation_object->get_image_id() ); ?>" />
|
||||
</a>
|
||||
</p>
|
||||
<?php if ( wc_product_sku_enabled() ) : ?>
|
||||
<p class="sku form-row form-row-last">
|
||||
<label><?php _e( 'SKU', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Enter a SKU for this variation or leave blank to use the parent product SKU.', 'woocommerce' ) ); ?></label>
|
||||
<input type="text" size="5" name="variable_sku[<?php echo $loop; ?>]" value="<?php if ( isset( $_sku ) ) echo esc_attr( $_sku ); ?>" placeholder="<?php echo esc_attr( $parent_data['sku'] ); ?>" />
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<input type="hidden" name="variable_sku[<?php echo $loop; ?>]" value="<?php if ( isset( $_sku ) ) echo esc_attr( $_sku ); ?>" />
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if ( wc_product_sku_enabled() ) {
|
||||
woocommerce_wp_text_input( array(
|
||||
'id' => "variable_sku{$loop}",
|
||||
'name' => "variable_sku[{$loop}]",
|
||||
'value' => $variation_object->get_sku(),
|
||||
'placeholder' => $product_object->get_sku(),
|
||||
'label' => '<abbr title="' . __( 'Stock Keeping Unit', 'woocommerce' ) . '">' . __( 'SKU', 'woocommerce' ) . '</abbr>',
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'SKU refers to a Stock-keeping unit, a unique identifier for each distinct product and service that can be purchased.', 'woocommerce' ),
|
||||
'wrapper_class' => 'form-row form-row-last',
|
||||
) );
|
||||
}
|
||||
?>
|
||||
<p class="form-row form-row-full options">
|
||||
<label><input type="checkbox" class="checkbox" name="variable_enabled[<?php echo $loop; ?>]" <?php checked( $variation->post_status, 'publish' ); ?> /> <?php _e( 'Enabled', 'woocommerce' ); ?></label>
|
||||
|
||||
<label><input type="checkbox" class="checkbox variable_is_downloadable" name="variable_is_downloadable[<?php echo $loop; ?>]" <?php checked( isset( $_downloadable ) ? $_downloadable : '', 'yes' ); ?> /> <?php _e( 'Downloadable', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Enable this option if access is given to a downloadable file upon purchase of a product', 'woocommerce' ) ); ?></label>
|
||||
|
||||
<label><input type="checkbox" class="checkbox variable_is_virtual" name="variable_is_virtual[<?php echo $loop; ?>]" <?php checked( isset( $_virtual ) ? $_virtual : '', 'yes' ); ?> /> <?php _e( 'Virtual', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Enable this option if a product is not shipped or there is no shipping cost', 'woocommerce' ) ); ?></label>
|
||||
|
||||
<?php if ( get_option( 'woocommerce_manage_stock' ) == 'yes' ) : ?>
|
||||
|
||||
<label><input type="checkbox" class="checkbox variable_manage_stock" name="variable_manage_stock[<?php echo $loop; ?>]" <?php checked( isset( $_manage_stock ) ? $_manage_stock : '', 'yes' ); ?> /> <?php _e( 'Manage stock?', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Enable this option to enable stock management at variation level', 'woocommerce' ) ); ?></label>
|
||||
<label>
|
||||
<?php _e( 'Enabled', 'woocommerce' ); ?>:
|
||||
<input type="checkbox" class="checkbox" name="variable_enabled[<?php echo $loop; ?>]" <?php checked( $variation_object->get_status(), 'publish' ); ?> />
|
||||
</label>
|
||||
<label class="tips" data-tip="<?php _e( 'Enable this option if access is given to a downloadable file upon purchase of a product', 'woocommerce' ); ?>">
|
||||
<?php _e( 'Downloadable', 'woocommerce' ); ?>:
|
||||
<input type="checkbox" class="checkbox variable_is_downloadable" name="variable_is_downloadable[<?php echo $loop; ?>]" <?php checked( $variation_object->get_downloadable(), true ); ?> />
|
||||
</label>
|
||||
<label class="tips" data-tip="<?php _e( 'Enable this option if a product is not shipped or there is no shipping cost', 'woocommerce' ); ?>">
|
||||
<?php _e( 'Virtual', 'woocommerce' ); ?>:
|
||||
<input type="checkbox" class="checkbox variable_is_virtual" name="variable_is_virtual[<?php echo $loop; ?>]" <?php checked( $variation_object->get_virtual(), true ); ?> />
|
||||
</label>
|
||||
|
||||
<?php if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) : ?>
|
||||
<label class="tips" data-tip="<?php _e( 'Enable this option to enable stock management at variation level', 'woocommerce' ); ?>">
|
||||
<?php _e( 'Manage stock?', 'woocommerce' ); ?>
|
||||
<input type="checkbox" class="checkbox variable_manage_stock" name="variable_manage_stock[<?php echo $loop; ?>]" <?php checked( $variation_object->get_manage_stock(), true ); ?> />
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php do_action( 'woocommerce_variation_options', $loop, $variation_data, $variation ); ?>
|
||||
</p>
|
||||
|
||||
<div class="variable_pricing">
|
||||
<p class="form-row form-row-first">
|
||||
<label><?php echo __( 'Regular price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')'; ?></label>
|
||||
<input type="text" size="5" name="variable_regular_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_regular_price ) ) echo esc_attr( $_regular_price ); ?>" class="wc_input_price" placeholder="<?php esc_attr_e( 'Variation price (required)', 'woocommerce' ); ?>" />
|
||||
</p>
|
||||
<p class="form-row form-row-last">
|
||||
<label><?php echo __( 'Sale price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')'; ?> <a href="#" class="sale_schedule"><?php _e( 'Schedule', 'woocommerce' ); ?></a><a href="#" class="cancel_sale_schedule" style="display:none"><?php _e( 'Cancel schedule', 'woocommerce' ); ?></a></label>
|
||||
<input type="text" size="5" name="variable_sale_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_sale_price ) ) echo esc_attr( $_sale_price ); ?>" class="wc_input_price" />
|
||||
</p>
|
||||
|
||||
<div class="sale_price_dates_fields" style="display: none">
|
||||
<p class="form-row form-row-first">
|
||||
<label><?php _e( 'Sale start date', 'woocommerce' ); ?></label>
|
||||
<input type="text" class="sale_price_dates_from" name="variable_sale_price_dates_from[<?php echo $loop; ?>]" value="<?php echo ! empty( $_sale_price_dates_from ) ? date_i18n( 'Y-m-d', $_sale_price_dates_from ) : ''; ?>" placeholder="<?php echo esc_attr_x( 'From…', 'placeholder', 'woocommerce' ) ?> YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />
|
||||
</p>
|
||||
<p class="form-row form-row-last">
|
||||
<label><?php _e( 'Sale end date', 'woocommerce' ); ?></label>
|
||||
<input type="text" class="sale_price_dates_to" name="variable_sale_price_dates_to[<?php echo $loop; ?>]" value="<?php echo ! empty( $_sale_price_dates_to ) ? date_i18n( 'Y-m-d', $_sale_price_dates_to ) : ''; ?>" placeholder="<?php echo esc_attr_x( 'To…', 'placeholder', 'woocommerce' ) ?> YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
woocommerce_wp_text_input( array(
|
||||
'id' => "variable_regular_price_{$loop}",
|
||||
'name' => "variable_regular_price[{$loop}]",
|
||||
'value' => wc_format_localized_price( $variation_object->get_regular_price() ),
|
||||
'label' => __( 'Regular price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',
|
||||
'data_type' => 'price',
|
||||
'wrapper_class' => 'form-row form-row-first',
|
||||
) );
|
||||
|
||||
woocommerce_wp_text_input( array(
|
||||
'id' => "variable_sale_price{$loop}",
|
||||
'name' => "variable_sale_price[{$loop}]",
|
||||
'value' => wc_format_localized_price( $variation_object->get_sale_price() ),
|
||||
'data_type' => 'price',
|
||||
'label' => __( 'Sale price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')' . ' <a href="#" class="sale_schedule">' . __( 'Schedule', 'woocommerce' ) . '</a><a href="#" class="cancel_sale_schedule hidden">' . __( 'Cancel schedule', 'woocommerce' ) . '</a>',
|
||||
'wrapper_class' => 'form-row form-row-last',
|
||||
) );
|
||||
|
||||
$sale_price_dates_from = ( $date = $variation_object->get_date_on_sale_from() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = ( $date = $variation_object->get_date_on_sale_to() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
|
||||
echo '<div class="form-field sale_price_dates_fields hidden">
|
||||
<p class="form-row form-row-first">
|
||||
<label>' . __( 'Sale start date', 'woocommerce' ) . '</label>
|
||||
<input type="text" class="sale_price_dates_from" name="variable_sale_price_dates_from[' . $loop . ']" value="' . esc_attr( $sale_price_dates_from ) . '" placeholder="' . _x( 'From…', 'placeholder', 'woocommerce' ) . ' YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />
|
||||
</p>
|
||||
<p class="form-row form-row-last">
|
||||
<label>' . __( 'Sale end date', 'woocommerce' ) . '</label>
|
||||
<input type="text" class="sale_price_dates_to" name="variable_sale_price_dates_to[' . $loop . ']" id="_sale_price_dates_to" value="' . esc_attr( $sale_price_dates_to ) . '" placeholder="' . _x( 'To…', 'placeholder', 'woocommerce' ) . ' YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />
|
||||
</p>
|
||||
</div>';
|
||||
|
||||
/**
|
||||
* woocommerce_variation_options_pricing action.
|
||||
*
|
||||
|
@ -121,24 +136,35 @@ extract( $variation_data );
|
|||
?>
|
||||
</div>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_manage_stock' ) ) : ?>
|
||||
<?php if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) : ?>
|
||||
<div class="show_if_variation_manage_stock" style="display: none;">
|
||||
<p class="form-row form-row-first">
|
||||
<label><?php _e( 'Stock quantity', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Enter a quantity to enable stock management at variation level, or leave blank to use the parent product\'s options.', 'woocommerce' ) ); ?></label>
|
||||
<input type="number" size="5" name="variable_stock[<?php echo $loop; ?>]" value="<?php if ( isset( $_stock ) ) echo esc_attr( wc_stock_amount( $_stock ) ); ?>" step="any" />
|
||||
</p>
|
||||
<p class="form-row form-row-last">
|
||||
<label><?php _e( 'Allow backorders?', 'woocommerce' ); ?></label>
|
||||
<select name="variable_backorders[<?php echo $loop; ?>]">
|
||||
<?php
|
||||
foreach ( $parent_data['backorder_options'] as $key => $value ) {
|
||||
echo '<option value="' . esc_attr( $key ) . '" ' . selected( $key === $_backorders, true, false ) . '>' . esc_html( $value ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
woocommerce_wp_text_input( array(
|
||||
'id' => "variable_stock{$loop}",
|
||||
'name' => "variable_stock[{$loop}]",
|
||||
'value' => $variation_object->get_stock_quantity(),
|
||||
'label' => __( 'Stock quantity', 'woocommerce' ),
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'Enter a quantity to enable stock management at variation level, or leave blank to use the parent product\'s options.', 'woocommerce' ),
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'step' => 'any',
|
||||
),
|
||||
'data_type' => 'stock',
|
||||
'wrapper_class' => 'form-row form-row-first',
|
||||
) );
|
||||
|
||||
woocommerce_wp_select( array(
|
||||
'id' => "variable_backorders{$loop}",
|
||||
'name' => "variable_backorders[{$loop}]",
|
||||
'value' => $variation_object->get_backorders(),
|
||||
'label' => __( 'Allow backorders?', 'woocommerce' ),
|
||||
'options' => wc_get_product_backorder_options(),
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce' ),
|
||||
'wrapper_class' => 'form-row form-row-last',
|
||||
) );
|
||||
|
||||
/**
|
||||
* woocommerce_variation_options_inventory action.
|
||||
*
|
||||
|
@ -153,99 +179,109 @@ extract( $variation_data );
|
|||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="">
|
||||
<p class="form-row form-row-full">
|
||||
<label><?php _e( 'Stock status', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ); ?></label>
|
||||
<select name="variable_stock_status[<?php echo $loop; ?>]">
|
||||
<?php
|
||||
foreach ( $parent_data['stock_status_options'] as $key => $value ) {
|
||||
echo '<option value="' . esc_attr( $key === $_stock_status ? '' : $key ) . '" ' . selected( $key === $_stock_status, true, false ) . '>' . esc_html( $value ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<div>
|
||||
<?php
|
||||
woocommerce_wp_select( array(
|
||||
'id' => "variable_stock_status{$loop}",
|
||||
'name' => "variable_stock_status[{$loop}]",
|
||||
'value' => $variation_object->get_stock_status(),
|
||||
'label' => __( 'Stock status', 'woocommerce' ),
|
||||
'options' => wc_get_product_stock_status_options(),
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
|
||||
'wrapper_class' => 'form-row form-row-full',
|
||||
) );
|
||||
|
||||
if ( wc_product_weight_enabled() ) {
|
||||
woocommerce_wp_text_input( array(
|
||||
'id' => "variable_weight{$loop}",
|
||||
'name' => "variable_weight[{$loop}]",
|
||||
'value' => wc_format_localized_decimal( $variation_object->get_weight() ), // @todo need method to get raw unfiltered values in admin.
|
||||
'placeholder' => wc_format_localized_decimal( $product_object->get_weight() ),
|
||||
'label' => __( 'Weight', 'woocommerce' ) . ' (' . get_option( 'woocommerce_weight_unit' ) . ')',
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'Weight in decimal form', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'data_type' => 'decimal',
|
||||
'wrapper_class' => 'form-row form-row-first hide_if_variation_virtual',
|
||||
) );
|
||||
}
|
||||
|
||||
if ( wc_product_dimensions_enabled() ) {
|
||||
?><p class="form-field form-row dimensions_field hide_if_variation_virtual form-row-last">
|
||||
<label for="product_length"><?php echo __( 'Dimensions', 'woocommerce' ) . ' (' . get_option( 'woocommerce_dimension_unit' ) . ')'; ?></label>
|
||||
<?php echo wc_help_tip( __( 'Length x width x height in decimal form', 'woocommerce' ) ); ?>
|
||||
<span class="wrap">
|
||||
<input id="product_length" placeholder="<?php esc_attr_e( 'Length', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="variable_length[<?php echo $loop; ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_length() ) ); ?>" />
|
||||
<input placeholder="<?php esc_attr_e( 'Width', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="variable_width[<?php echo $loop; ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_width() ) ); ?>" />
|
||||
<input placeholder="<?php esc_attr_e( 'Height', 'woocommerce' ); ?>" class="input-text wc_input_decimal last" size="6" type="text" name="variable_height[<?php echo $loop; ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_height() ) ); ?>" />
|
||||
</span>
|
||||
</p><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* woocommerce_variation_options_dimensions action.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @param int $loop
|
||||
* @param array $variation_data
|
||||
* @param WP_Post $variation
|
||||
*/
|
||||
do_action( 'woocommerce_variation_options_dimensions', $loop, $variation_data, $variation );
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php if ( wc_product_weight_enabled() || wc_product_dimensions_enabled() ) : ?>
|
||||
<div>
|
||||
<?php if ( wc_product_weight_enabled() ) : ?>
|
||||
<p class="form-row hide_if_variation_virtual form-row-first">
|
||||
<label><?php echo __( 'Weight', 'woocommerce' ) . ' (' . esc_html( get_option( 'woocommerce_weight_unit' ) ) . ')'; ?> <?php echo wc_help_tip( __( 'Enter a weight for this variation or leave blank to use the parent product weight.', 'woocommerce' ) ); ?></a></label>
|
||||
<input type="text" size="5" name="variable_weight[<?php echo $loop; ?>]" value="<?php if ( isset( $_weight ) ) echo esc_attr( $_weight ); ?>" placeholder="<?php echo esc_attr( $parent_data['weight'] ); ?>" class="wc_input_decimal" />
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<p> </p>
|
||||
<?php endif; ?>
|
||||
<?php if ( wc_product_dimensions_enabled() ) : ?>
|
||||
<p class="form-row dimensions_field hide_if_variation_virtual form-row-last">
|
||||
<label for="product_length"><?php echo __( 'Dimensions (L×W×H)', 'woocommerce' ) . ' (' . esc_html( get_option( 'woocommerce_dimension_unit' ) ) . ')'; ?></label>
|
||||
<input id="product_length" class="input-text wc_input_decimal" size="6" type="text" name="variable_length[<?php echo $loop; ?>]" value="<?php if ( isset( $_length ) ) echo esc_attr( $_length ); ?>" placeholder="<?php echo esc_attr( $parent_data['length'] ); ?>" />
|
||||
<input class="input-text wc_input_decimal" size="6" type="text" name="variable_width[<?php echo $loop; ?>]" value="<?php if ( isset( $_width ) ) echo esc_attr( $_width ); ?>" placeholder="<?php echo esc_attr( $parent_data['width'] ); ?>" />
|
||||
<input class="input-text wc_input_decimal last" size="6" type="text" name="variable_height[<?php echo $loop; ?>]" value="<?php if ( isset( $_height ) ) echo esc_attr( $_height ); ?>" placeholder="<?php echo esc_attr( $parent_data['height'] ); ?>" />
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<p> </p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_variation_options_dimensions action.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @param int $loop
|
||||
* @param array $variation_data
|
||||
* @param WP_Post $variation
|
||||
*/
|
||||
do_action( 'woocommerce_variation_options_dimensions', $loop, $variation_data, $variation );
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div>
|
||||
<p class="form-row hide_if_variation_virtual form-row-full"><label><?php _e( 'Shipping class', 'woocommerce' ); ?></label> <?php
|
||||
$args = array(
|
||||
'taxonomy' => 'product_shipping_class',
|
||||
'hide_empty' => 0,
|
||||
'show_option_none' => __( 'Same as parent', 'woocommerce' ),
|
||||
'name' => 'variable_shipping_class[' . $loop . ']',
|
||||
'id' => '',
|
||||
'selected' => isset( $shipping_class ) ? esc_attr( $shipping_class ) : '',
|
||||
'echo' => 0,
|
||||
);
|
||||
|
||||
echo wp_dropdown_categories( $args );
|
||||
wp_dropdown_categories( array(
|
||||
'taxonomy' => 'product_shipping_class',
|
||||
'hide_empty' => 0,
|
||||
'show_option_none' => __( 'Same as parent', 'woocommerce' ),
|
||||
'name' => 'variable_shipping_class[' . $loop . ']',
|
||||
'id' => '',
|
||||
'selected' => $variation_object->get_shipping_class_id(),
|
||||
) );
|
||||
?></p>
|
||||
|
||||
<?php if ( wc_tax_enabled() ) : ?>
|
||||
<p class="form-row form-row-full">
|
||||
<label><?php _e( 'Tax class', 'woocommerce' ); ?></label>
|
||||
<select name="variable_tax_class[<?php echo $loop; ?>]">
|
||||
<option value="parent" <?php selected( is_null( $_tax_class ), true ); ?>><?php _e( 'Same as parent', 'woocommerce' ); ?></option>
|
||||
<?php
|
||||
foreach ( $parent_data['tax_class_options'] as $key => $value )
|
||||
echo '<option value="' . esc_attr( $key ) . '" ' . selected( $key === $_tax_class, true, false ) . '>' . esc_html( $value ) . '</option>';
|
||||
?></select>
|
||||
</p>
|
||||
<?php
|
||||
if ( wc_tax_enabled() ) {
|
||||
woocommerce_wp_select( array(
|
||||
'id' => "variable_tax_class{$loop}",
|
||||
'name' => "variable_tax_class[{$loop}]",
|
||||
'value' => $variation_object->get_tax_class(),
|
||||
'label' => __( 'Tax class', 'woocommerce' ),
|
||||
'options' => array_merge( array( 'parent' => __( 'Same as parent', 'woocommerce' ) ), wc_get_product_tax_class_options() ), // @todo rename to inherit - make sure get_tax_class returns this value too.
|
||||
'desc_tip' => 'true',
|
||||
'description' => __( 'Choose a tax class for this product. Tax classes are used to apply different tax rates specific to certain types of product.', 'woocommerce' ),
|
||||
'wrapper_class' => 'form-row form-row-full',
|
||||
) );
|
||||
|
||||
<?php
|
||||
/**
|
||||
* woocommerce_variation_options_tax action.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @param int $loop
|
||||
* @param array $variation_data
|
||||
* @param WP_Post $variation
|
||||
*/
|
||||
do_action( 'woocommerce_variation_options_tax', $loop, $variation_data, $variation );
|
||||
?>
|
||||
<?php endif; ?>
|
||||
/**
|
||||
* woocommerce_variation_options_tax action.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @param int $loop
|
||||
* @param array $variation_data
|
||||
* @param WP_Post $variation
|
||||
*/
|
||||
do_action( 'woocommerce_variation_options_tax', $loop, $variation_data, $variation );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div>
|
||||
<p class="form-row form-row-full">
|
||||
<label><?php _e( 'Variation description', 'woocommerce' ); ?></label>
|
||||
<textarea name="variable_description[<?php echo $loop; ?>]" rows="3" style="width:100%;"><?php echo isset( $variation_data['_variation_description'] ) ? esc_textarea( $variation_data['_variation_description'] ) : ''; ?></textarea>
|
||||
</p>
|
||||
<?php
|
||||
woocommerce_wp_textarea_input( array(
|
||||
'id' => "variable_description{$loop}",
|
||||
'name' => "variable_description[{$loop}]",
|
||||
'value' => $variation_object->get_description(),
|
||||
'label' => __( 'Description', 'woocommerce' ),
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'Enter an optional description for this variation.', 'woocommerce' ),
|
||||
'wrapper_class' => 'form-row form-row-full',
|
||||
) );
|
||||
?>
|
||||
</div>
|
||||
<div class="show_if_variation_downloadable" style="display: none;">
|
||||
<div class="form-row form-row-full downloadable_files">
|
||||
|
@ -260,8 +296,8 @@ extract( $variation_data );
|
|||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if ( $_downloadable_files ) {
|
||||
foreach ( $_downloadable_files as $key => $file ) {
|
||||
if ( $downloads = $variation_object->get_downloads() ) {
|
||||
foreach ( $downloads as $key => $file ) {
|
||||
if ( ! is_array( $file ) ) {
|
||||
$file = array(
|
||||
'file' => $file,
|
||||
|
@ -292,16 +328,39 @@ extract( $variation_data );
|
|||
</div>
|
||||
</div>
|
||||
<div class="show_if_variation_downloadable" style="display: none;">
|
||||
<p class="form-row form-row-first">
|
||||
<label><?php _e( 'Download limit', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Leave blank for unlimited re-downloads.', 'woocommerce' ) ); ?></a></label>
|
||||
<input type="number" size="5" name="variable_download_limit[<?php echo $loop; ?>]" value="<?php if ( isset( $_download_limit ) ) echo esc_attr( $_download_limit ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'woocommerce' ); ?>" step="1" min="0" />
|
||||
</p>
|
||||
<p class="form-row form-row-last">
|
||||
<label><?php _e( 'Download expiry', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Enter the number of days before a download link expires, or leave blank.', 'woocommerce' ) ); ?></a></label>
|
||||
<input type="number" size="5" name="variable_download_expiry[<?php echo $loop; ?>]" value="<?php if ( isset( $_download_expiry ) ) echo esc_attr( $_download_expiry ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'woocommerce' ); ?>" step="1" min="0" />
|
||||
</p>
|
||||
|
||||
<?php
|
||||
woocommerce_wp_text_input( array(
|
||||
'id' => "variable_download_limit{$loop}",
|
||||
'name' => "variable_download_limit[{$loop}]",
|
||||
'value' => $variation_object->get_download_limit() < 0 ? '' : $variation_object->get_download_limit(),
|
||||
'label' => __( 'Download limit', 'woocommerce' ),
|
||||
'placeholder' => __( 'Unlimited', 'woocommerce' ),
|
||||
'description' => __( 'Leave blank for unlimited re-downloads.', 'woocommerce' ),
|
||||
'type' => 'number',
|
||||
'desc_tip' => true,
|
||||
'custom_attributes' => array(
|
||||
'step' => '1',
|
||||
'min' => '0',
|
||||
),
|
||||
'wrapper_class' => 'form-row form-row-first',
|
||||
) );
|
||||
|
||||
woocommerce_wp_text_input( array(
|
||||
'id' => "variable_download_expiry{$loop}",
|
||||
'name' => "variable_download_expiry[{$loop}]",
|
||||
'value' => $variation_object->get_download_expiry() < 0 ? '' : $variation_object->get_download_expiry(),
|
||||
'label' => __( 'Download expiry', 'woocommerce' ),
|
||||
'placeholder' => __( 'Never', 'woocommerce' ),
|
||||
'description' => __( 'Enter the number of days before a download link expires, or leave blank.', 'woocommerce' ),
|
||||
'type' => 'number',
|
||||
'desc_tip' => true,
|
||||
'custom_attributes' => array(
|
||||
'step' => '1',
|
||||
'min' => '0',
|
||||
),
|
||||
'wrapper_class' => 'form-row form-row-last',
|
||||
) );
|
||||
|
||||
/**
|
||||
* woocommerce_variation_options_download action.
|
||||
*
|
||||
|
|
|
@ -76,7 +76,7 @@ class WC_Report_Stock extends WP_List_Table {
|
|||
public function column_default( $item, $column_name ) {
|
||||
global $product;
|
||||
|
||||
if ( ! $product || $product->id !== $item->id ) {
|
||||
if ( ! $product || $product->get_id() !== $item->id ) {
|
||||
$product = wc_get_product( $item->id );
|
||||
}
|
||||
|
||||
|
|
|
@ -72,13 +72,6 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
$classes_options = array();
|
||||
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, include( 'views/settings-tax.php' ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -39,10 +39,10 @@ return apply_filters( 'woocommerce_tax_settings', array(
|
|||
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_shipping_tax_class',
|
||||
'css' => 'min-width:150px;',
|
||||
'default' => '',
|
||||
'default' => 'inherit',
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'options' => array( '' => __( 'Shipping tax class based on cart items', 'woocommerce' ), 'standard' => __( 'Standard', 'woocommerce' ) ) + $classes_options,
|
||||
'options' => array_merge( array( 'inherit' => __( 'Shipping tax class based on cart items', 'woocommerce' ) ), wc_get_product_tax_class_options() ),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
|
|
|
@ -218,12 +218,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<span class="input-text-wrap">
|
||||
<select class="stock_status" name="_stock_status">
|
||||
<?php
|
||||
$options = array(
|
||||
'' => __( '— No Change —', 'woocommerce' ),
|
||||
'instock' => __( 'In stock', 'woocommerce' ),
|
||||
'outofstock' => __( 'Out of stock', 'woocommerce' ),
|
||||
);
|
||||
foreach ( $options as $key => $value ) {
|
||||
echo '<option value="">' . __( '— No Change —', 'woocommerce' ) . '</option>';
|
||||
|
||||
foreach ( wc_get_product_stock_status_options() as $key => $value ) {
|
||||
echo '<option value="' . esc_attr( $key ) . '">' . $value . '</option>';
|
||||
}
|
||||
?>
|
||||
|
@ -277,13 +274,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<span class="input-text-wrap">
|
||||
<select class="backorders" name="_backorders">
|
||||
<?php
|
||||
$options = array(
|
||||
'' => __( '— No Change —', 'woocommerce' ),
|
||||
'no' => __( 'Do not allow', 'woocommerce' ),
|
||||
'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
|
||||
'yes' => __( 'Allow', 'woocommerce' ),
|
||||
);
|
||||
foreach ( $options as $key => $value ) {
|
||||
echo '<option value="">' . __( '— No Change —', 'woocommerce' ) . '</option>';
|
||||
|
||||
foreach ( wc_get_product_backorder_options() as $key => $value ) {
|
||||
echo '<option value="' . esc_attr( $key ) . '">' . $value . '</option>';
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -162,11 +162,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<span class="input-text-wrap">
|
||||
<select class="stock_status" name="_stock_status">
|
||||
<?php
|
||||
$options = array(
|
||||
'instock' => __( 'In stock', 'woocommerce' ),
|
||||
'outofstock' => __( 'Out of stock', 'woocommerce' ),
|
||||
);
|
||||
foreach ( $options as $key => $value ) {
|
||||
foreach ( wc_get_product_stock_status_options() as $key => $value ) {
|
||||
echo '<option value="' . esc_attr( $key ) . '">' . $value . '</option>';
|
||||
}
|
||||
?>
|
||||
|
@ -197,12 +193,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<span class="input-text-wrap">
|
||||
<select class="backorders" name="_backorders">
|
||||
<?php
|
||||
$options = array(
|
||||
'no' => __( 'Do not allow', 'woocommerce' ),
|
||||
'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
|
||||
'yes' => __( 'Allow', 'woocommerce' ),
|
||||
);
|
||||
foreach ( $options as $key => $value ) {
|
||||
foreach ( wc_get_product_backorder_options() as $key => $value ) {
|
||||
echo '<option value="' . esc_attr( $key ) . '">' . $value . '</option>';
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -27,6 +27,7 @@ function woocommerce_wp_text_input( $field ) {
|
|||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
|
||||
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false;
|
||||
$data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
|
||||
|
||||
switch ( $data_type ) {
|
||||
|
@ -61,16 +62,19 @@ function woocommerce_wp_text_input( $field ) {
|
|||
}
|
||||
}
|
||||
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> ';
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
|
||||
<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
}
|
||||
|
||||
echo '<input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
}
|
||||
|
||||
|
@ -103,6 +107,8 @@ function woocommerce_wp_textarea_input( $field ) {
|
|||
$field['style'] = isset( $field['style'] ) ? $field['style'] : '';
|
||||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false;
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
|
||||
// Custom attribute handling
|
||||
$custom_attributes = array();
|
||||
|
@ -114,16 +120,19 @@ function woocommerce_wp_textarea_input( $field ) {
|
|||
}
|
||||
}
|
||||
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><textarea class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" rows="2" cols="20" ' . implode( ' ', $custom_attributes ) . '>' . esc_textarea( $field['value'] ) . '</textarea> ';
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
|
||||
<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
}
|
||||
|
||||
echo '<textarea class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" rows="2" cols="20" ' . implode( ' ', $custom_attributes ) . '>' . esc_textarea( $field['value'] ) . '</textarea> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
}
|
||||
|
||||
|
@ -142,6 +151,7 @@ function woocommerce_wp_checkbox( $field ) {
|
|||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes';
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false;
|
||||
|
||||
// Custom attribute handling
|
||||
$custom_attributes = array();
|
||||
|
@ -153,15 +163,17 @@ function woocommerce_wp_checkbox( $field ) {
|
|||
}
|
||||
}
|
||||
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="checkbox" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' ' . implode( ' ', $custom_attributes ) . '/> ';
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
|
||||
<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
}
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
echo '<input type="checkbox" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' ' . implode( ' ', $custom_attributes ) . '/> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
|
@ -181,6 +193,7 @@ function woocommerce_wp_select( $field ) {
|
|||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false;
|
||||
|
||||
// Custom attribute handling
|
||||
$custom_attributes = array();
|
||||
|
@ -192,7 +205,14 @@ function woocommerce_wp_select( $field ) {
|
|||
}
|
||||
}
|
||||
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" ' . implode( ' ', $custom_attributes ) . '>';
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
|
||||
<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
|
||||
|
||||
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
}
|
||||
|
||||
echo '<select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" ' . implode( ' ', $custom_attributes ) . '>';
|
||||
|
||||
foreach ( $field['options'] as $key => $value ) {
|
||||
echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
|
||||
|
@ -200,14 +220,10 @@ function woocommerce_wp_select( $field ) {
|
|||
|
||||
echo '</select> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
}
|
||||
|
||||
|
@ -225,8 +241,15 @@ function woocommerce_wp_radio( $field ) {
|
|||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false;
|
||||
|
||||
echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><legend>' . wp_kses_post( $field['label'] ) . '</legend><ul class="wc-radios">';
|
||||
echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><legend>' . wp_kses_post( $field['label'] ) . '</legend>';
|
||||
|
||||
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
}
|
||||
|
||||
echo '<ul class="wc-radios">';
|
||||
|
||||
foreach ( $field['options'] as $key => $value ) {
|
||||
|
||||
|
@ -242,13 +265,8 @@ function woocommerce_wp_radio( $field ) {
|
|||
}
|
||||
echo '</ul>';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo wc_help_tip( $field['description'] );
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
echo '</fieldset>';
|
||||
|
|
|
@ -270,18 +270,18 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
|
|||
if ( has_post_thumbnail( $product->get_variation_id() ) ) {
|
||||
// Add variation image if set.
|
||||
$variation = wc_get_product( $product->get_variation_id() );
|
||||
$attachment_ids[] = $variation->get_thumbnail_id();
|
||||
$attachment_ids[] = $variation->get_image_id();
|
||||
} elseif ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
// Otherwise use the parent product featured image if set.
|
||||
$attachment_ids[] = $product->get_thumbnail_id();
|
||||
$attachment_ids[] = $product->get_image_id();
|
||||
}
|
||||
} else {
|
||||
// Add featured image.
|
||||
if ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
$attachment_ids[] = $product->get_thumbnail_id();
|
||||
$attachment_ids[] = $product->get_image_id();
|
||||
}
|
||||
// Add gallery images.
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_attachment_ids() );
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() );
|
||||
}
|
||||
|
||||
// Build image data.
|
||||
|
@ -883,11 +883,11 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
|
|||
}
|
||||
|
||||
if ( ! empty( $gallery ) ) {
|
||||
$product->set_gallery_attachment_ids( $gallery );
|
||||
$product->set_gallery_image_ids( $gallery );
|
||||
}
|
||||
} else {
|
||||
$product->set_thumbnail_id( '' );
|
||||
$product->set_gallery_attachment_ids( array() );
|
||||
$product->set_gallery_image_ids( array() );
|
||||
}
|
||||
|
||||
return $product;
|
||||
|
|
|
@ -271,7 +271,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
|
||||
return array(
|
||||
'title' => $product->get_title(),
|
||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->id,
|
||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->get_id(),
|
||||
'created_at' => $this->server->format_datetime( $product->get_post_data()->post_date_gmt ),
|
||||
'updated_at' => $this->server->format_datetime( $product->get_post_data()->post_modified_gmt ),
|
||||
'type' => $product->product_type,
|
||||
|
@ -317,17 +317,17 @@ class WC_API_Products extends WC_API_Resource {
|
|||
'related_ids' => array_map( 'absint', array_values( $product->get_related() ) ),
|
||||
'upsell_ids' => array_map( 'absint', $product->get_upsells() ),
|
||||
'cross_sell_ids' => array_map( 'absint', $product->get_cross_sells() ),
|
||||
'categories' => wp_get_post_terms( $product->id, 'product_cat', array( 'fields' => 'names' ) ),
|
||||
'tags' => wp_get_post_terms( $product->id, 'product_tag', array( 'fields' => 'names' ) ),
|
||||
'categories' => wp_get_post_terms( $product->get_id(), 'product_cat', array( 'fields' => 'names' ) ),
|
||||
'tags' => wp_get_post_terms( $product->get_id(), 'product_tag', array( 'fields' => 'names' ) ),
|
||||
'images' => $this->get_images( $product ),
|
||||
'featured_src' => wp_get_attachment_url( get_post_thumbnail_id( $product->is_type( 'variation' ) ? $product->variation_id : $product->id ) ),
|
||||
'featured_src' => wp_get_attachment_url( get_post_thumbnail_id( $product->is_type( 'variation' ) ? $product->variation_id : $product->get_id() ) ),
|
||||
'attributes' => $this->get_attributes( $product ),
|
||||
'downloads' => $this->get_downloads( $product ),
|
||||
'download_limit' => (int) $product->download_limit,
|
||||
'download_expiry' => (int) $product->download_expiry,
|
||||
'download_type' => $product->download_type,
|
||||
'purchase_note' => apply_filters( 'the_content', $product->purchase_note ),
|
||||
'total_sales' => metadata_exists( 'post', $product->id, 'total_sales' ) ? (int) get_post_meta( $product->id, 'total_sales', true ) : 0,
|
||||
'total_sales' => metadata_exists( 'post', $product->get_id(), 'total_sales' ) ? (int) get_post_meta( $product->get_id(), 'total_sales', true ) : 0,
|
||||
'variations' => array(),
|
||||
'parent' => array(),
|
||||
);
|
||||
|
@ -412,20 +412,20 @@ class WC_API_Products extends WC_API_Resource {
|
|||
// add variation image if set
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_variation_id() );
|
||||
|
||||
} elseif ( has_post_thumbnail( $product->id ) ) {
|
||||
} elseif ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
|
||||
// otherwise use the parent product featured image if set
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->id );
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_id() );
|
||||
}
|
||||
} else {
|
||||
|
||||
// add featured image
|
||||
if ( has_post_thumbnail( $product->id ) ) {
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->id );
|
||||
if ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_id() );
|
||||
}
|
||||
|
||||
// add gallery images
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_attachment_ids() );
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() );
|
||||
}
|
||||
|
||||
// build image data
|
||||
|
@ -516,7 +516,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
'position' => $attribute['position'],
|
||||
'visible' => (bool) $attribute['is_visible'],
|
||||
'variation' => (bool) $attribute['is_variation'],
|
||||
'options' => $this->get_attribute_options( $product->id, $attribute ),
|
||||
'options' => $this->get_attribute_options( $product->get_id(), $attribute ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -679,7 +679,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
|
||||
return array(
|
||||
'title' => $product->get_title(),
|
||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->id,
|
||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->get_id(),
|
||||
'created_at' => $this->server->format_datetime( $product->get_post_data()->post_date_gmt ),
|
||||
'updated_at' => $this->server->format_datetime( $product->get_post_data()->post_modified_gmt ),
|
||||
'type' => $product->product_type,
|
||||
|
@ -728,17 +728,17 @@ class WC_API_Products extends WC_API_Resource {
|
|||
'upsell_ids' => array_map( 'absint', $product->get_upsells() ),
|
||||
'cross_sell_ids' => array_map( 'absint', $product->get_cross_sells() ),
|
||||
'parent_id' => $product->post->post_parent,
|
||||
'categories' => wp_get_post_terms( $product->id, 'product_cat', array( 'fields' => 'names' ) ),
|
||||
'tags' => wp_get_post_terms( $product->id, 'product_tag', array( 'fields' => 'names' ) ),
|
||||
'categories' => wp_get_post_terms( $product->get_id(), 'product_cat', array( 'fields' => 'names' ) ),
|
||||
'tags' => wp_get_post_terms( $product->get_id(), 'product_tag', array( 'fields' => 'names' ) ),
|
||||
'images' => $this->get_images( $product ),
|
||||
'featured_src' => (string) wp_get_attachment_url( get_post_thumbnail_id( $product->is_type( 'variation' ) ? $product->variation_id : $product->id ) ),
|
||||
'featured_src' => (string) wp_get_attachment_url( get_post_thumbnail_id( $product->is_type( 'variation' ) ? $product->variation_id : $product->get_id() ) ),
|
||||
'attributes' => $this->get_attributes( $product ),
|
||||
'downloads' => $this->get_downloads( $product ),
|
||||
'download_limit' => (int) $product->download_limit,
|
||||
'download_expiry' => (int) $product->download_expiry,
|
||||
'download_type' => $product->download_type,
|
||||
'purchase_note' => wpautop( do_shortcode( wp_kses_post( $product->purchase_note ) ) ),
|
||||
'total_sales' => metadata_exists( 'post', $product->id, 'total_sales' ) ? (int) get_post_meta( $product->id, 'total_sales', true ) : 0,
|
||||
'total_sales' => metadata_exists( 'post', $product->get_id(), 'total_sales' ) ? (int) get_post_meta( $product->get_id(), 'total_sales', true ) : 0,
|
||||
'variations' => array(),
|
||||
'parent' => array(),
|
||||
);
|
||||
|
@ -1680,20 +1680,20 @@ class WC_API_Products extends WC_API_Resource {
|
|||
// Add variation image if set
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_variation_id() );
|
||||
|
||||
} elseif ( has_post_thumbnail( $product->id ) ) {
|
||||
} elseif ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
|
||||
// Otherwise use the parent product featured image if set
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->id );
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_id() );
|
||||
}
|
||||
} else {
|
||||
|
||||
// Add featured image
|
||||
if ( has_post_thumbnail( $product->id ) ) {
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->id );
|
||||
if ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_id() );
|
||||
}
|
||||
|
||||
// Add gallery images
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_attachment_ids() );
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() );
|
||||
}
|
||||
|
||||
// Build image data
|
||||
|
@ -1953,7 +1953,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
'position' => (int) $attribute['position'],
|
||||
'visible' => (bool) $attribute['is_visible'],
|
||||
'variation' => (bool) $attribute['is_variation'],
|
||||
'options' => $this->get_attribute_options( $product->id, $attribute ),
|
||||
'options' => $this->get_attribute_options( $product->get_id(), $attribute ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1119,7 +1119,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
private function get_product_data( $product ) {
|
||||
return array(
|
||||
'title' => $product->get_title(),
|
||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->id,
|
||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->get_id(),
|
||||
'created_at' => $this->server->format_datetime( $product->get_post_data()->post_date_gmt ),
|
||||
'updated_at' => $this->server->format_datetime( $product->get_post_data()->post_modified_gmt ),
|
||||
'type' => $product->product_type,
|
||||
|
@ -1168,17 +1168,17 @@ class WC_API_Products extends WC_API_Resource {
|
|||
'upsell_ids' => array_map( 'absint', $product->get_upsells() ),
|
||||
'cross_sell_ids' => array_map( 'absint', $product->get_cross_sells() ),
|
||||
'parent_id' => $product->is_type( 'variation' ) ? $product->parent->id : $product->post->post_parent,
|
||||
'categories' => wp_get_post_terms( $product->id, 'product_cat', array( 'fields' => 'names' ) ),
|
||||
'tags' => wp_get_post_terms( $product->id, 'product_tag', array( 'fields' => 'names' ) ),
|
||||
'categories' => wp_get_post_terms( $product->get_id(), 'product_cat', array( 'fields' => 'names' ) ),
|
||||
'tags' => wp_get_post_terms( $product->get_id(), 'product_tag', array( 'fields' => 'names' ) ),
|
||||
'images' => $this->get_images( $product ),
|
||||
'featured_src' => (string) wp_get_attachment_url( get_post_thumbnail_id( $product->is_type( 'variation' ) ? $product->variation_id : $product->id ) ),
|
||||
'featured_src' => (string) wp_get_attachment_url( get_post_thumbnail_id( $product->is_type( 'variation' ) ? $product->variation_id : $product->get_id() ) ),
|
||||
'attributes' => $this->get_attributes( $product ),
|
||||
'downloads' => $this->get_downloads( $product ),
|
||||
'download_limit' => (int) $product->download_limit,
|
||||
'download_expiry' => (int) $product->download_expiry,
|
||||
'download_type' => $product->download_type,
|
||||
'purchase_note' => wpautop( do_shortcode( wp_kses_post( $product->purchase_note ) ) ),
|
||||
'total_sales' => metadata_exists( 'post', $product->id, 'total_sales' ) ? (int) get_post_meta( $product->id, 'total_sales', true ) : 0,
|
||||
'total_sales' => metadata_exists( 'post', $product->get_id(), 'total_sales' ) ? (int) get_post_meta( $product->get_id(), 'total_sales', true ) : 0,
|
||||
'variations' => array(),
|
||||
'parent' => array(),
|
||||
'grouped_products' => array(),
|
||||
|
@ -2202,20 +2202,20 @@ class WC_API_Products extends WC_API_Resource {
|
|||
// Add variation image if set
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_variation_id() );
|
||||
|
||||
} elseif ( has_post_thumbnail( $product->id ) ) {
|
||||
} elseif ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
|
||||
// Otherwise use the parent product featured image if set
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->id );
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_id() );
|
||||
}
|
||||
} else {
|
||||
|
||||
// Add featured image
|
||||
if ( has_post_thumbnail( $product->id ) ) {
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->id );
|
||||
if ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_id() );
|
||||
}
|
||||
|
||||
// Add gallery images
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_attachment_ids() );
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() );
|
||||
}
|
||||
|
||||
// Build image data
|
||||
|
@ -2534,7 +2534,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
'position' => (int) $attribute['position'],
|
||||
'visible' => (bool) $attribute['is_visible'],
|
||||
'variation' => (bool) $attribute['is_variation'],
|
||||
'options' => $this->get_attribute_options( $product->id, $attribute ),
|
||||
'options' => $this->get_attribute_options( $product->get_id(), $attribute ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -611,135 +611,18 @@ class WC_AJAX {
|
|||
die( -1 );
|
||||
}
|
||||
|
||||
global $post;
|
||||
|
||||
$post_id = intval( $_POST['post_id'] );
|
||||
$post = get_post( $post_id ); // Set $post global so its available like within the admin screens
|
||||
$loop = intval( $_POST['loop'] );
|
||||
|
||||
$variation = array(
|
||||
'post_title' => 'Product #' . $post_id . ' Variation',
|
||||
'post_content' => '',
|
||||
'post_status' => 'publish',
|
||||
'post_author' => get_current_user_id(),
|
||||
'post_parent' => $post_id,
|
||||
'post_type' => 'product_variation',
|
||||
'menu_order' => -1,
|
||||
);
|
||||
|
||||
$variation_id = wp_insert_post( $variation );
|
||||
|
||||
do_action( 'woocommerce_create_product_variation', $variation_id );
|
||||
|
||||
if ( $variation_id ) {
|
||||
$variation = get_post( $variation_id );
|
||||
$variation_meta = get_post_meta( $variation_id );
|
||||
$variation_data = array();
|
||||
$shipping_classes = get_the_terms( $variation_id, 'product_shipping_class' );
|
||||
$variation_fields = array(
|
||||
'_sku' => '',
|
||||
'_stock' => '',
|
||||
'_regular_price' => '',
|
||||
'_sale_price' => '',
|
||||
'_weight' => '',
|
||||
'_length' => '',
|
||||
'_width' => '',
|
||||
'_height' => '',
|
||||
'_download_limit' => '',
|
||||
'_download_expiry' => '',
|
||||
'_downloadable_files' => '',
|
||||
'_downloadable' => '',
|
||||
'_virtual' => '',
|
||||
'_thumbnail_id' => '',
|
||||
'_sale_price_dates_from' => '',
|
||||
'_sale_price_dates_to' => '',
|
||||
'_manage_stock' => '',
|
||||
'_stock_status' => '',
|
||||
'_backorders' => null,
|
||||
'_tax_class' => null,
|
||||
'_variation_description' => '',
|
||||
);
|
||||
|
||||
foreach ( $variation_fields as $field => $value ) {
|
||||
$variation_data[ $field ] = isset( $variation_meta[ $field ][0] ) ? maybe_unserialize( $variation_meta[ $field ][0] ) : $value;
|
||||
}
|
||||
|
||||
// Add the variation attributes
|
||||
$variation_data = array_merge( $variation_data, wc_get_product_variation_attributes( $variation_id ) );
|
||||
|
||||
// Formatting
|
||||
$variation_data['_regular_price'] = wc_format_localized_price( $variation_data['_regular_price'] );
|
||||
$variation_data['_sale_price'] = wc_format_localized_price( $variation_data['_sale_price'] );
|
||||
$variation_data['_weight'] = wc_format_localized_decimal( $variation_data['_weight'] );
|
||||
$variation_data['_length'] = wc_format_localized_decimal( $variation_data['_length'] );
|
||||
$variation_data['_width'] = wc_format_localized_decimal( $variation_data['_width'] );
|
||||
$variation_data['_height'] = wc_format_localized_decimal( $variation_data['_height'] );
|
||||
$variation_data['_thumbnail_id'] = absint( $variation_data['_thumbnail_id'] );
|
||||
$variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url( $variation_data['_thumbnail_id'] ) : '';
|
||||
$variation_data['shipping_class'] = $shipping_classes && ! is_wp_error( $shipping_classes ) ? current( $shipping_classes )->term_id : '';
|
||||
$variation_data['menu_order'] = $variation->menu_order;
|
||||
$variation_data['_stock'] = wc_stock_amount( $variation_data['_stock'] );
|
||||
|
||||
// Get tax classes
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
$tax_class_options = array();
|
||||
$tax_class_options[''] = __( 'Standard', 'woocommerce' );
|
||||
|
||||
if ( ! empty( $tax_classes ) ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$tax_class_options[ sanitize_title( $class ) ] = esc_attr( $class );
|
||||
}
|
||||
}
|
||||
|
||||
// Set backorder options
|
||||
$backorder_options = array(
|
||||
'no' => __( 'Do not allow', 'woocommerce' ),
|
||||
'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
|
||||
'yes' => __( 'Allow', 'woocommerce' ),
|
||||
);
|
||||
|
||||
// set stock status options
|
||||
$stock_status_options = array(
|
||||
'instock' => __( 'In stock', 'woocommerce' ),
|
||||
'outofstock' => __( 'Out of stock', 'woocommerce' ),
|
||||
);
|
||||
|
||||
// Get attributes
|
||||
$attributes = (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) );
|
||||
|
||||
$parent_data = array(
|
||||
'id' => $post_id,
|
||||
'attributes' => $attributes,
|
||||
'tax_class_options' => $tax_class_options,
|
||||
'sku' => get_post_meta( $post_id, '_sku', true ),
|
||||
'weight' => wc_format_localized_decimal( get_post_meta( $post_id, '_weight', true ) ),
|
||||
'length' => wc_format_localized_decimal( get_post_meta( $post_id, '_length', true ) ),
|
||||
'width' => wc_format_localized_decimal( get_post_meta( $post_id, '_width', true ) ),
|
||||
'height' => wc_format_localized_decimal( get_post_meta( $post_id, '_height', true ) ),
|
||||
'tax_class' => get_post_meta( $post_id, '_tax_class', true ),
|
||||
'backorder_options' => $backorder_options,
|
||||
'stock_status_options' => $stock_status_options,
|
||||
);
|
||||
|
||||
if ( ! $parent_data['weight'] ) {
|
||||
$parent_data['weight'] = wc_format_localized_decimal( 0 );
|
||||
}
|
||||
|
||||
if ( ! $parent_data['length'] ) {
|
||||
$parent_data['length'] = wc_format_localized_decimal( 0 );
|
||||
}
|
||||
|
||||
if ( ! $parent_data['width'] ) {
|
||||
$parent_data['width'] = wc_format_localized_decimal( 0 );
|
||||
}
|
||||
|
||||
if ( ! $parent_data['height'] ) {
|
||||
$parent_data['height'] = wc_format_localized_decimal( 0 );
|
||||
}
|
||||
|
||||
include( 'admin/meta-boxes/views/html-variation-admin.php' );
|
||||
}
|
||||
global $post; // Set $post global so its available, like within the admin screens
|
||||
|
||||
$product_id = intval( $_POST['post_id'] );
|
||||
$post = get_post( $product_id );
|
||||
$loop = intval( $_POST['loop'] );
|
||||
$product_object = wc_get_product( $product_id );
|
||||
$variation_object = new WC_Product_Variation();
|
||||
$variation_object->set_parent_id( $product_id );
|
||||
$variation_id = $variation_object->save();
|
||||
$variation = get_post( $variation_id );
|
||||
$variation_data = array_merge( array_map( 'maybe_unserialize', get_post_custom( $variation_id ) ), wc_get_product_variation_attributes( $variation_id ) ); // kept for BW compat.
|
||||
include( 'admin/meta-boxes/views/html-variation-admin.php' );
|
||||
die();
|
||||
}
|
||||
|
||||
|
@ -1179,7 +1062,7 @@ class WC_AJAX {
|
|||
if ( $_product->exists() && $_product->managing_stock() && isset( $order_item_qty[ $item_id ] ) && $order_item_qty[ $item_id ] > 0 ) {
|
||||
$stock_change = apply_filters( 'woocommerce_reduce_order_stock_quantity', $order_item_qty[ $item_id ], $item_id );
|
||||
$new_stock = $_product->reduce_stock( $stock_change );
|
||||
$item_name = $_product->get_sku() ? $_product->get_sku() : $_product->id;
|
||||
$item_name = $_product->get_sku() ? $_product->get_sku() : $_product->get_id();
|
||||
|
||||
if ( ! empty( $_product->variation_id ) ) {
|
||||
$note = sprintf( __( 'Item %1$s variation #%2$s stock reduced from %3$s to %4$s.', 'woocommerce' ), $item_name, $_product->variation_id, $new_stock + $stock_change, $new_stock );
|
||||
|
@ -1225,7 +1108,7 @@ class WC_AJAX {
|
|||
$old_stock = $_product->get_stock_quantity();
|
||||
$stock_change = apply_filters( 'woocommerce_restore_order_stock_quantity', $order_item_qty[ $item_id ], $item_id );
|
||||
$new_quantity = $_product->increase_stock( $stock_change );
|
||||
$item_name = $_product->get_sku() ? $_product->get_sku() : $_product->id;
|
||||
$item_name = $_product->get_sku() ? $_product->get_sku() : $_product->get_id();
|
||||
|
||||
if ( ! empty( $_product->variation_id ) ) {
|
||||
$note = sprintf( __( 'Item %1$s variation #%2$s stock increased from %3$s to %4$s.', 'woocommerce' ), $item_name, $_product->variation_id, $old_stock, $new_quantity );
|
||||
|
@ -1817,7 +1700,7 @@ class WC_AJAX {
|
|||
|
||||
$order->add_order_note( sprintf( __( 'Item #%s stock increased from %1$s to %2$s.', 'woocommerce' ), $order_item['product_id'], $old_stock, $new_quantity ) );
|
||||
|
||||
do_action( 'woocommerce_restock_refunded_item', $_product->id, $old_stock, $new_quantity, $order, $_product );
|
||||
do_action( 'woocommerce_restock_refunded_item', $_product->get_id(), $old_stock, $new_quantity, $order, $_product );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1994,146 +1877,37 @@ class WC_AJAX {
|
|||
|
||||
check_ajax_referer( 'load-variations', 'security' );
|
||||
|
||||
// Check permissions again and make sure we have what we need
|
||||
if ( ! current_user_can( 'edit_products' ) || empty( $_POST['product_id'] ) || empty( $_POST['attributes'] ) ) {
|
||||
if ( ! current_user_can( 'edit_products' ) || empty( $_POST['product_id'] ) ) {
|
||||
die( -1 );
|
||||
}
|
||||
|
||||
// Set $post global so its available, like within the admin screens
|
||||
global $post;
|
||||
|
||||
$product_id = absint( $_POST['product_id'] );
|
||||
$post = get_post( $product_id ); // Set $post global so its available like within the admin screens
|
||||
$per_page = ! empty( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 10;
|
||||
$page = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
|
||||
|
||||
// Get attributes
|
||||
$attributes = array();
|
||||
$posted_attributes = wp_unslash( $_POST['attributes'] );
|
||||
|
||||
foreach ( $posted_attributes as $key => $value ) {
|
||||
$attributes[ $key ] = array_map( 'wc_clean', $value );
|
||||
}
|
||||
|
||||
// Get tax classes
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
$tax_class_options = array();
|
||||
$tax_class_options[''] = __( 'Standard', 'woocommerce' );
|
||||
|
||||
if ( ! empty( $tax_classes ) ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$tax_class_options[ sanitize_title( $class ) ] = esc_attr( $class );
|
||||
}
|
||||
}
|
||||
|
||||
// Set backorder options
|
||||
$backorder_options = array(
|
||||
'no' => __( 'Do not allow', 'woocommerce' ),
|
||||
'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
|
||||
'yes' => __( 'Allow', 'woocommerce' ),
|
||||
);
|
||||
|
||||
// set stock status options
|
||||
$stock_status_options = array(
|
||||
'instock' => __( 'In stock', 'woocommerce' ),
|
||||
'outofstock' => __( 'Out of stock', 'woocommerce' ),
|
||||
);
|
||||
|
||||
$parent_data = array(
|
||||
'id' => $product_id,
|
||||
'attributes' => $attributes,
|
||||
'tax_class_options' => $tax_class_options,
|
||||
'sku' => get_post_meta( $product_id, '_sku', true ),
|
||||
'weight' => wc_format_localized_decimal( get_post_meta( $product_id, '_weight', true ) ),
|
||||
'length' => wc_format_localized_decimal( get_post_meta( $product_id, '_length', true ) ),
|
||||
'width' => wc_format_localized_decimal( get_post_meta( $product_id, '_width', true ) ),
|
||||
'height' => wc_format_localized_decimal( get_post_meta( $product_id, '_height', true ) ),
|
||||
'tax_class' => get_post_meta( $product_id, '_tax_class', true ),
|
||||
'backorder_options' => $backorder_options,
|
||||
'stock_status_options' => $stock_status_options,
|
||||
);
|
||||
|
||||
if ( ! $parent_data['weight'] ) {
|
||||
$parent_data['weight'] = wc_format_localized_decimal( 0 );
|
||||
}
|
||||
|
||||
if ( ! $parent_data['length'] ) {
|
||||
$parent_data['length'] = wc_format_localized_decimal( 0 );
|
||||
}
|
||||
|
||||
if ( ! $parent_data['width'] ) {
|
||||
$parent_data['width'] = wc_format_localized_decimal( 0 );
|
||||
}
|
||||
|
||||
if ( ! $parent_data['height'] ) {
|
||||
$parent_data['height'] = wc_format_localized_decimal( 0 );
|
||||
}
|
||||
|
||||
// Get variations
|
||||
$args = apply_filters( 'woocommerce_ajax_admin_get_variations_args', array(
|
||||
'post_type' => 'product_variation',
|
||||
'post_status' => array( 'private', 'publish' ),
|
||||
'posts_per_page' => $per_page,
|
||||
'paged' => $page,
|
||||
'orderby' => array( 'menu_order' => 'ASC', 'ID' => 'DESC' ),
|
||||
'post_parent' => $product_id,
|
||||
), $product_id );
|
||||
|
||||
$variations = get_posts( $args );
|
||||
$loop = 0;
|
||||
$loop = 0;
|
||||
$product_id = absint( $_POST['product_id'] );
|
||||
$post = get_post( $product_id );
|
||||
$product_object = wc_get_product( $product_id );
|
||||
$per_page = ! empty( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 10;
|
||||
$page = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
|
||||
$variations = wc_get_products( array(
|
||||
'status' => array( 'private', 'publish' ),
|
||||
'type' => 'variation',
|
||||
'parent' => $product_id,
|
||||
'limit' => $per_page,
|
||||
'page' => $page,
|
||||
'orderby' => array(
|
||||
'menu_order' => 'ASC',
|
||||
'ID' => 'DESC',
|
||||
),
|
||||
'return' => 'objects',
|
||||
) );
|
||||
|
||||
if ( $variations ) {
|
||||
|
||||
foreach ( $variations as $variation ) {
|
||||
$variation_id = absint( $variation->ID );
|
||||
$variation_meta = get_post_meta( $variation_id );
|
||||
$variation_data = array();
|
||||
$shipping_classes = get_the_terms( $variation_id, 'product_shipping_class' );
|
||||
$variation_fields = array(
|
||||
'_sku' => '',
|
||||
'_stock' => '',
|
||||
'_regular_price' => '',
|
||||
'_sale_price' => '',
|
||||
'_weight' => '',
|
||||
'_length' => '',
|
||||
'_width' => '',
|
||||
'_height' => '',
|
||||
'_download_limit' => '',
|
||||
'_download_expiry' => '',
|
||||
'_downloadable_files' => '',
|
||||
'_downloadable' => '',
|
||||
'_virtual' => '',
|
||||
'_thumbnail_id' => '',
|
||||
'_sale_price_dates_from' => '',
|
||||
'_sale_price_dates_to' => '',
|
||||
'_manage_stock' => '',
|
||||
'_stock_status' => '',
|
||||
'_backorders' => null,
|
||||
'_tax_class' => null,
|
||||
'_variation_description' => '',
|
||||
);
|
||||
|
||||
foreach ( $variation_fields as $field => $value ) {
|
||||
$variation_data[ $field ] = isset( $variation_meta[ $field ][0] ) ? maybe_unserialize( $variation_meta[ $field ][0] ) : $value;
|
||||
}
|
||||
|
||||
// Add the variation attributes
|
||||
$variation_data = array_merge( $variation_data, wc_get_product_variation_attributes( $variation_id ) );
|
||||
|
||||
// Formatting
|
||||
$variation_data['_regular_price'] = wc_format_localized_price( $variation_data['_regular_price'] );
|
||||
$variation_data['_sale_price'] = wc_format_localized_price( $variation_data['_sale_price'] );
|
||||
$variation_data['_weight'] = wc_format_localized_decimal( $variation_data['_weight'] );
|
||||
$variation_data['_length'] = wc_format_localized_decimal( $variation_data['_length'] );
|
||||
$variation_data['_width'] = wc_format_localized_decimal( $variation_data['_width'] );
|
||||
$variation_data['_height'] = wc_format_localized_decimal( $variation_data['_height'] );
|
||||
$variation_data['_thumbnail_id'] = absint( $variation_data['_thumbnail_id'] );
|
||||
$variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url( $variation_data['_thumbnail_id'] ) : '';
|
||||
$variation_data['shipping_class'] = $shipping_classes && ! is_wp_error( $shipping_classes ) ? current( $shipping_classes )->term_id : '';
|
||||
$variation_data['menu_order'] = $variation->menu_order;
|
||||
$variation_data['_stock'] = '' === $variation_data['_stock'] ? '' : wc_stock_amount( $variation_data['_stock'] );
|
||||
|
||||
foreach ( $variations as $variation_object ) {
|
||||
$variation_id = $variation_object->get_id();
|
||||
$variation_data = array_merge( array_map( 'maybe_unserialize', get_post_custom( $variation_id ) ), wc_get_product_variation_attributes( $variation_id ) ); // kept for BW compat.
|
||||
include( 'admin/meta-boxes/views/html-variation-admin.php' );
|
||||
|
||||
$loop++;
|
||||
}
|
||||
}
|
||||
|
@ -2142,7 +1916,7 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
/**
|
||||
* Save variations via AJAX. @todo CRUD
|
||||
* Save variations via AJAX.
|
||||
*/
|
||||
public static function save_variations() {
|
||||
ob_start();
|
||||
|
@ -2154,26 +1928,12 @@ class WC_AJAX {
|
|||
die( -1 );
|
||||
}
|
||||
|
||||
// Remove previous meta box errors
|
||||
$product_id = absint( $_POST['product_id'] );
|
||||
WC_Admin_Meta_Boxes::$meta_box_errors = array();
|
||||
|
||||
$product_id = absint( $_POST['product_id'] );
|
||||
$product_type = empty( $_POST['product-type'] ) ? 'simple' : sanitize_title( stripslashes( $_POST['product-type'] ) );
|
||||
|
||||
$product_type_terms = wp_get_object_terms( $product_id, 'product_type' );
|
||||
|
||||
// If the product type hasn't been set or it has changed, update it before saving variations
|
||||
if ( empty( $product_type_terms ) || sanitize_title( current( $product_type_terms )->name ) !== $product_type ) {
|
||||
wp_set_object_terms( $product_id, $product_type, 'product_type' );
|
||||
}
|
||||
|
||||
WC_Meta_Box_Product_Data::save_variations( $product_id, get_post( $product_id ) );
|
||||
|
||||
do_action( 'woocommerce_ajax_save_product_variations', $product_id );
|
||||
|
||||
// Clear cache/transients
|
||||
wc_delete_product_transients( $product_id );
|
||||
|
||||
if ( $errors = WC_Admin_Meta_Boxes::$meta_box_errors ) {
|
||||
echo '<div class="error notice is-dismissible">';
|
||||
|
||||
|
|
|
@ -227,21 +227,21 @@ class WC_Cart {
|
|||
update_meta_cache( 'post', wp_list_pluck( $cart, 'product_id' ) );
|
||||
|
||||
foreach ( $cart as $key => $values ) {
|
||||
$_product = wc_get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );
|
||||
$product = wc_get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );
|
||||
|
||||
if ( ! empty( $_product ) && $_product->exists() && $values['quantity'] > 0 ) {
|
||||
if ( ! empty( $product ) && $product->exists() && $values['quantity'] > 0 ) {
|
||||
|
||||
if ( ! $_product->is_purchasable() ) {
|
||||
if ( ! $product->is_purchasable() ) {
|
||||
|
||||
// Flag to indicate the stored cart should be update
|
||||
$update_cart_session = true;
|
||||
wc_add_notice( sprintf( __( '%s has been removed from your cart because it can no longer be purchased. Please contact us if you need assistance.', 'woocommerce' ), $_product->get_title() ), 'error' );
|
||||
wc_add_notice( sprintf( __( '%s has been removed from your cart because it can no longer be purchased. Please contact us if you need assistance.', 'woocommerce' ), $product->get_title() ), 'error' );
|
||||
do_action( 'woocommerce_remove_cart_item_from_session', $key, $values );
|
||||
|
||||
} else {
|
||||
|
||||
// Put session data into array. Run through filter so other plugins can load their own session data
|
||||
$session_data = array_merge( $values, array( 'data' => $_product ) );
|
||||
$session_data = array_merge( $values, array( 'data' => $product ) );
|
||||
$this->cart_contents[ $key ] = apply_filters( 'woocommerce_get_cart_item_from_session', $session_data, $values, $key );
|
||||
|
||||
}
|
||||
|
@ -428,14 +428,13 @@ class WC_Cart {
|
|||
$quantities = array();
|
||||
|
||||
foreach ( $this->get_cart() as $cart_item_key => $values ) {
|
||||
$_product = $values['data'];
|
||||
$product = $values['data'];
|
||||
|
||||
if ( $_product->is_type( 'variation' ) && true === $_product->managing_stock() ) {
|
||||
// Variation has stock levels defined so its handled individually
|
||||
$quantities[ $values['variation_id'] ] = isset( $quantities[ $values['variation_id'] ] ) ? $quantities[ $values['variation_id'] ] + $values['quantity'] : $values['quantity'];
|
||||
} else {
|
||||
$quantities[ $values['product_id'] ] = isset( $quantities[ $values['product_id'] ] ) ? $quantities[ $values['product_id'] ] + $values['quantity'] : $values['quantity'];
|
||||
if ( ! $product->managing_stock() && $product->get_parent_id() ) {
|
||||
$product = wc_get_product( $product->get_parent_id() );
|
||||
}
|
||||
|
||||
$quantities[ $product->get_id() ] = isset( $quantities[ $product->get_id() ] ) ? $quantities[ $product->get_id() ] + $values['quantity'] : $values['quantity'];
|
||||
}
|
||||
|
||||
return $quantities;
|
||||
|
@ -450,9 +449,9 @@ class WC_Cart {
|
|||
$return = true;
|
||||
|
||||
foreach ( $this->get_cart() as $cart_item_key => $values ) {
|
||||
$_product = $values['data'];
|
||||
$product = $values['data'];
|
||||
|
||||
if ( ! $_product || ! $_product->exists() || 'trash' === $_product->post->post_status ) {
|
||||
if ( ! $product || ! $product->exists() || 'trash' === $product->get_status() ) {
|
||||
$this->set_quantity( $cart_item_key, 0 );
|
||||
$return = new WP_Error( 'invalid', __( 'An item which is no longer available was removed from your cart.', 'woocommerce' ) );
|
||||
}
|
||||
|
@ -474,34 +473,38 @@ class WC_Cart {
|
|||
|
||||
// First stock check loop
|
||||
foreach ( $this->get_cart() as $cart_item_key => $values ) {
|
||||
$_product = $values['data'];
|
||||
$product = $values['data'];
|
||||
|
||||
/**
|
||||
* Check stock based on stock-status.
|
||||
*/
|
||||
if ( ! $_product->is_in_stock() ) {
|
||||
$error->add( 'out-of-stock', sprintf( __( 'Sorry, "%s" is not in stock. Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $_product->get_title() ) );
|
||||
if ( ! $product->is_in_stock() ) {
|
||||
$error->add( 'out-of-stock', sprintf( __( 'Sorry, "%s" is not in stock. Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $product->get_title() ) );
|
||||
return $error;
|
||||
}
|
||||
|
||||
if ( ! $_product->managing_stock() ) {
|
||||
continue;
|
||||
$product_to_check = $product;
|
||||
|
||||
if ( ! $product_to_check->managing_stock() && $product_to_check->get_parent_id() ) {
|
||||
$product_to_check = wc_get_product( $product_to_check->get_parent_id() );
|
||||
}
|
||||
|
||||
$check_qty = $_product->is_type( 'variation' ) && true === $_product->managing_stock() ? $product_qty_in_cart[ $values['variation_id'] ] : $product_qty_in_cart[ $values['product_id'] ];
|
||||
if ( ! $product_to_check->managing_stock() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check stock based on all items in the cart.
|
||||
*/
|
||||
if ( ! $_product->has_enough_stock( $check_qty ) ) {
|
||||
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s in stock). Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $_product->get_title(), $_product->get_stock_quantity() ) );
|
||||
if ( ! $product_to_check->has_enough_stock( $product_qty_in_cart[ $product_to_check->get_id() ] ) ) {
|
||||
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s in stock). Please edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $product_to_check->get_title(), $product_to_check->get_stock_quantity() ) );
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finally consider any held stock, from pending orders.
|
||||
*/
|
||||
if ( get_option( 'woocommerce_hold_stock_minutes' ) > 0 && ! $_product->backorders_allowed() ) {
|
||||
if ( get_option( 'woocommerce_hold_stock_minutes' ) > 0 && ! $product_to_check->backorders_allowed() ) {
|
||||
$order_id = isset( WC()->session->order_awaiting_payment ) ? absint( WC()->session->order_awaiting_payment ) : 0;
|
||||
$held_stock = $wpdb->get_var(
|
||||
$wpdb->prepare( "
|
||||
|
@ -515,21 +518,14 @@ class WC_Cart {
|
|||
AND posts.post_type IN ( '" . implode( "','", wc_get_order_types() ) . "' )
|
||||
AND posts.post_status = 'wc-pending'
|
||||
AND posts.ID != %d;",
|
||||
$_product->is_type( 'variation' ) && true === $_product->managing_stock() ? '_variation_id' : '_product_id',
|
||||
$_product->is_type( 'variation' ) && true === $_product->managing_stock() ? $values['variation_id'] : $values['product_id'],
|
||||
$product_to_check->is_type( 'variation' ) ? '_variation_id' : '_product_id',
|
||||
$product_to_check->get_id(),
|
||||
$order_id
|
||||
)
|
||||
);
|
||||
|
||||
$not_enough_stock = false;
|
||||
|
||||
if ( $_product->is_type( 'variation' ) && 'parent' === $_product->managing_stock() && $_product->parent->get_stock_quantity() < ( $held_stock + $check_qty ) ) {
|
||||
$not_enough_stock = true;
|
||||
} elseif ( $_product->get_stock_quantity() < ( $held_stock + $check_qty ) ) {
|
||||
$not_enough_stock = true;
|
||||
}
|
||||
if ( $not_enough_stock ) {
|
||||
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order right now. Please try again in %2$d minutes or edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $_product->get_title(), get_option( 'woocommerce_hold_stock_minutes' ) ) );
|
||||
if ( $product_to_check->get_stock_quantity() < ( $held_stock + $product_qty_in_cart[ $product_to_check->get_id() ] ) ) {
|
||||
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order right now. Please try again in %2$d minutes or edit your cart and try again. We apologise for any inconvenience caused.', 'woocommerce' ), $product_to_check->get_title(), get_option( 'woocommerce_hold_stock_minutes' ) ) );
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
|
@ -894,7 +890,7 @@ class WC_Cart {
|
|||
$variation_id = absint( $variation_id );
|
||||
|
||||
// Ensure we don't add a variation to the cart directly by variation ID
|
||||
if ( 'product_variation' == get_post_type( $product_id ) ) {
|
||||
if ( 'product_variation' === get_post_type( $product_id ) ) {
|
||||
$variation_id = $product_id;
|
||||
$product_id = wp_get_post_parent_id( $variation_id );
|
||||
}
|
||||
|
@ -941,24 +937,21 @@ class WC_Cart {
|
|||
}
|
||||
|
||||
// Stock check - this time accounting for whats already in-cart
|
||||
if ( $managing_stock = $product_data->managing_stock() ) {
|
||||
$product_to_check = $product_data;
|
||||
|
||||
if ( ! $product_to_check->managing_stock() && $product_to_check->get_parent_id() ) {
|
||||
$product_to_check = wc_get_product( $product_to_check->get_parent_id() );
|
||||
}
|
||||
|
||||
if ( $product_to_check->managing_stock() ) {
|
||||
$products_qty_in_cart = $this->get_cart_item_quantities();
|
||||
|
||||
if ( $product_data->is_type( 'variation' ) && true === $managing_stock ) {
|
||||
$check_qty = isset( $products_qty_in_cart[ $variation_id ] ) ? $products_qty_in_cart[ $variation_id ] : 0;
|
||||
} else {
|
||||
$check_qty = isset( $products_qty_in_cart[ $product_id ] ) ? $products_qty_in_cart[ $product_id ] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check stock based on all items in the cart.
|
||||
*/
|
||||
if ( ! $product_data->has_enough_stock( $check_qty + $quantity ) ) {
|
||||
if ( ! $product_to_check->has_enough_stock( $products_qty_in_cart[ $product_to_check->get_id() ] + $quantity ) ) {
|
||||
throw new Exception( sprintf(
|
||||
'<a href="%s" class="button wc-forward">%s</a> %s',
|
||||
wc_get_cart_url(),
|
||||
__( 'View Cart', 'woocommerce' ),
|
||||
sprintf( __( 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), $product_data->get_stock_quantity(), $check_qty )
|
||||
sprintf( __( 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), $product_to_check->get_stock_quantity(), $products_qty_in_cart[ $product_to_check->get_id() ] )
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
@ -1130,15 +1123,15 @@ class WC_Cart {
|
|||
* Calculate subtotals for items. This is done first so that discount logic can use the values.
|
||||
*/
|
||||
foreach ( $cart as $cart_item_key => $values ) {
|
||||
$_product = $values['data'];
|
||||
$line_price = $_product->get_price() * $values['quantity'];
|
||||
$product = $values['data'];
|
||||
$line_price = $product->get_price() * $values['quantity'];
|
||||
$line_subtotal = 0;
|
||||
$line_subtotal_tax = 0;
|
||||
|
||||
/**
|
||||
* No tax to calculate.
|
||||
*/
|
||||
if ( ! $_product->is_taxable() ) {
|
||||
if ( ! $product->is_taxable() ) {
|
||||
|
||||
// Subtotal is the undiscounted price
|
||||
$this->subtotal += $line_price;
|
||||
|
@ -1159,17 +1152,17 @@ class WC_Cart {
|
|||
} elseif ( $this->prices_include_tax ) {
|
||||
|
||||
// Get base tax rates
|
||||
if ( empty( $shop_tax_rates[ $_product->tax_class ] ) ) {
|
||||
$shop_tax_rates[ $_product->tax_class ] = WC_Tax::get_base_tax_rates( $_product->tax_class );
|
||||
if ( empty( $shop_tax_rates[ $product->get_tax_class( true ) ] ) ) {
|
||||
$shop_tax_rates[ $product->get_tax_class( true ) ] = WC_Tax::get_base_tax_rates( $product->get_tax_class( true ) );
|
||||
}
|
||||
|
||||
// Get item tax rates
|
||||
if ( empty( $tax_rates[ $_product->get_tax_class() ] ) ) {
|
||||
$tax_rates[ $_product->get_tax_class() ] = WC_Tax::get_rates( $_product->get_tax_class() );
|
||||
if ( empty( $tax_rates[ $product->get_tax_class() ] ) ) {
|
||||
$tax_rates[ $product->get_tax_class() ] = WC_Tax::get_rates( $product->get_tax_class() );
|
||||
}
|
||||
|
||||
$base_tax_rates = $shop_tax_rates[ $_product->tax_class ];
|
||||
$item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
|
||||
$base_tax_rates = $shop_tax_rates[ $product->get_tax_class( true ) ];
|
||||
$item_tax_rates = $tax_rates[ $product->get_tax_class() ];
|
||||
|
||||
/**
|
||||
* ADJUST TAX - Calculations when base tax is not equal to the item tax.
|
||||
|
@ -1209,11 +1202,11 @@ class WC_Cart {
|
|||
} else {
|
||||
|
||||
// Get item tax rates
|
||||
if ( empty( $tax_rates[ $_product->get_tax_class() ] ) ) {
|
||||
$tax_rates[ $_product->get_tax_class() ] = WC_Tax::get_rates( $_product->get_tax_class() );
|
||||
if ( empty( $tax_rates[ $product->get_tax_class() ] ) ) {
|
||||
$tax_rates[ $product->get_tax_class() ] = WC_Tax::get_rates( $product->get_tax_class() );
|
||||
}
|
||||
|
||||
$item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
|
||||
$item_tax_rates = $tax_rates[ $product->get_tax_class() ];
|
||||
|
||||
// Base tax for line before discount - we will store this in the order data
|
||||
$taxes = WC_Tax::calc_tax( $line_price, $item_tax_rates );
|
||||
|
@ -1235,11 +1228,11 @@ class WC_Cart {
|
|||
*/
|
||||
foreach ( $cart as $cart_item_key => $values ) {
|
||||
|
||||
$_product = $values['data'];
|
||||
$product = $values['data'];
|
||||
|
||||
// Prices
|
||||
$base_price = $_product->get_price();
|
||||
$line_price = $_product->get_price() * $values['quantity'];
|
||||
$base_price = $product->get_price();
|
||||
$line_price = $product->get_price() * $values['quantity'];
|
||||
|
||||
// Tax data
|
||||
$taxes = array();
|
||||
|
@ -1248,7 +1241,7 @@ class WC_Cart {
|
|||
/**
|
||||
* No tax to calculate.
|
||||
*/
|
||||
if ( ! $_product->is_taxable() ) {
|
||||
if ( ! $product->is_taxable() ) {
|
||||
|
||||
// Discounted Price (price with any pre-tax discounts applied)
|
||||
$discounted_price = $this->get_discounted_price( $values, $base_price, true );
|
||||
|
@ -1262,8 +1255,8 @@ class WC_Cart {
|
|||
*/
|
||||
} elseif ( $this->prices_include_tax ) {
|
||||
|
||||
$base_tax_rates = $shop_tax_rates[ $_product->tax_class ];
|
||||
$item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
|
||||
$base_tax_rates = $shop_tax_rates[ $product->get_tax_class( true ) ];
|
||||
$item_tax_rates = $tax_rates[ $product->get_tax_class() ];
|
||||
|
||||
/**
|
||||
* ADJUST TAX - Calculations when base tax is not equal to the item tax.
|
||||
|
@ -1330,7 +1323,7 @@ class WC_Cart {
|
|||
*/
|
||||
} else {
|
||||
|
||||
$item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
|
||||
$item_tax_rates = $tax_rates[ $product->get_tax_class() ];
|
||||
|
||||
// Work out a new base price without the shop's base tax
|
||||
$taxes = WC_Tax::calc_tax( $line_price, $item_tax_rates );
|
||||
|
@ -1362,7 +1355,7 @@ class WC_Cart {
|
|||
*
|
||||
* Tax exclusive prices are not affected.
|
||||
*/
|
||||
if ( ! $_product->is_taxable() || $this->prices_include_tax ) {
|
||||
if ( ! $product->is_taxable() || $this->prices_include_tax ) {
|
||||
$this->cart_contents[ $cart_item_key ]['line_total'] = round( $line_total + $line_tax - wc_round_tax_total( $line_tax ), $this->dp );
|
||||
$this->cart_contents[ $cart_item_key ]['line_subtotal'] = round( $line_subtotal + $line_subtotal_tax - wc_round_tax_total( $line_subtotal_tax ), $this->dp );
|
||||
$this->cart_contents[ $cart_item_key ]['line_tax'] = wc_round_tax_total( $line_tax );
|
||||
|
@ -1526,8 +1519,8 @@ class WC_Cart {
|
|||
|
||||
if ( ! empty( $this->cart_contents ) ) {
|
||||
foreach ( $this->cart_contents as $cart_item_key => $values ) {
|
||||
$_product = $values['data'];
|
||||
if ( $_product->needs_shipping() ) {
|
||||
$product = $values['data'];
|
||||
if ( $product->needs_shipping() ) {
|
||||
$needs_shipping = true;
|
||||
}
|
||||
}
|
||||
|
@ -2113,17 +2106,17 @@ class WC_Cart {
|
|||
/**
|
||||
* Get the product row price per item.
|
||||
*
|
||||
* @param WC_Product $_product
|
||||
* @param WC_Product $product
|
||||
* @return string formatted price
|
||||
*/
|
||||
public function get_product_price( $_product ) {
|
||||
public function get_product_price( $product ) {
|
||||
if ( 'excl' === $this->tax_display_cart ) {
|
||||
$product_price = $_product->get_price_excluding_tax();
|
||||
$product_price = $product->get_price_excluding_tax();
|
||||
} else {
|
||||
$product_price = $_product->get_price_including_tax();
|
||||
$product_price = $product->get_price_including_tax();
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_cart_product_price', wc_price( $product_price ), $_product );
|
||||
return apply_filters( 'woocommerce_cart_product_price', wc_price( $product_price ), $product );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2133,21 +2126,21 @@ class WC_Cart {
|
|||
*
|
||||
* When on the checkout (review order), this will get the subtotal based on the customer's tax rate rather than the base rate.
|
||||
*
|
||||
* @param WC_Product $_product
|
||||
* @param WC_Product $product
|
||||
* @param int $quantity
|
||||
* @return string formatted price
|
||||
*/
|
||||
public function get_product_subtotal( $_product, $quantity ) {
|
||||
public function get_product_subtotal( $product, $quantity ) {
|
||||
|
||||
$price = $_product->get_price();
|
||||
$taxable = $_product->is_taxable();
|
||||
$price = $product->get_price();
|
||||
$taxable = $product->is_taxable();
|
||||
|
||||
// Taxable
|
||||
if ( $taxable ) {
|
||||
|
||||
if ( 'excl' === $this->tax_display_cart ) {
|
||||
|
||||
$row_price = $_product->get_price_excluding_tax( $quantity );
|
||||
$row_price = $product->get_price_excluding_tax( $quantity );
|
||||
$product_subtotal = wc_price( $row_price );
|
||||
|
||||
if ( $this->prices_include_tax && $this->tax_total > 0 ) {
|
||||
|
@ -2155,7 +2148,7 @@ class WC_Cart {
|
|||
}
|
||||
} else {
|
||||
|
||||
$row_price = $_product->get_price_including_tax( $quantity );
|
||||
$row_price = $product->get_price_including_tax( $quantity );
|
||||
$product_subtotal = wc_price( $row_price );
|
||||
|
||||
if ( ! $this->prices_include_tax && $this->tax_total > 0 ) {
|
||||
|
@ -2171,7 +2164,7 @@ class WC_Cart {
|
|||
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_cart_product_subtotal', $product_subtotal, $_product, $quantity, $this );
|
||||
return apply_filters( 'woocommerce_cart_product_subtotal', $product_subtotal, $product, $quantity, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1194,8 +1194,8 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
}
|
||||
|
||||
$valid = false;
|
||||
$product_cats = wc_get_product_cat_ids( $product->id );
|
||||
$product_ids = array( $product->id, ( isset( $product->variation_id ) ? $product->variation_id : 0 ), $product->get_parent() );
|
||||
$product_cats = wc_get_product_cat_ids( $product->get_id() );
|
||||
$product_ids = array( $product->get_id(), ( isset( $product->variation_id ) ? $product->variation_id : 0 ), $product->get_parent() );
|
||||
|
||||
// Specific products get the discount
|
||||
if ( sizeof( $this->get_product_ids() ) && sizeof( array_intersect( $product_ids, $this->get_product_ids() ) ) ) {
|
||||
|
@ -1230,7 +1230,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
if ( in_array( $product->variation_id, $product_ids_on_sale, true ) ) {
|
||||
$valid = false;
|
||||
}
|
||||
} elseif ( in_array( $product->id, $product_ids_on_sale, true ) ) {
|
||||
} elseif ( in_array( $product->get_id(), $product_ids_on_sale, true ) ) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -506,7 +506,7 @@ class WC_Emails {
|
|||
*/
|
||||
public function low_stock( $product ) {
|
||||
$subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product low in stock', 'woocommerce' ) );
|
||||
$message = sprintf( __( '%s is low in stock.', 'woocommerce' ), html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) ) . ' ' . sprintf( __( 'There are %d left', 'woocommerce' ), html_entity_decode( strip_tags( $product->get_total_stock() ) ) );
|
||||
$message = sprintf( __( '%s is low in stock.', 'woocommerce' ), html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) ) . ' ' . sprintf( __( 'There are %d left', 'woocommerce' ), html_entity_decode( strip_tags( $product->get_stock_quantity() ) ) );
|
||||
|
||||
wp_mail(
|
||||
apply_filters( 'woocommerce_email_recipient_low_stock', get_option( 'woocommerce_stock_email_recipient' ), $product ),
|
||||
|
|
|
@ -221,7 +221,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
*/
|
||||
public function set_backorder_meta() {
|
||||
if ( $this->get_product()->backorders_require_notification() && $this->get_product()->is_on_backorder( $this->get_quantity() ) ) {
|
||||
$this->add_meta_data( apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $this->get_quantity() - max( 0, $this->get_product()->get_total_stock() ), true );
|
||||
$this->add_meta_data( apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $this->get_quantity() - max( 0, $this->get_product()->get_stock_quantity() ), true );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,11 +364,15 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
if ( ! is_a( $product, 'WC_Product' ) ) {
|
||||
$this->error( 'order_item_product_invalid_product', __( 'Invalid product', 'woocommerce' ) );
|
||||
}
|
||||
$this->set_product_id( $product->get_id() );
|
||||
if ( $product->is_type( 'variation' ) ) {
|
||||
$this->set_product_id( $product->get_parent_id() );
|
||||
$this->set_variation_id( $product->get_id() );
|
||||
$this->set_variation( is_callable( array( $product, 'get_variation_attributes' ) ) ? $product->get_variation_attributes() : array() );
|
||||
} else {
|
||||
$this->set_product_id( $product->get_id() );
|
||||
}
|
||||
$this->set_name( $product->get_title() );
|
||||
$this->set_tax_class( $product->get_tax_class() );
|
||||
$this->set_variation_id( is_callable( array( $product, 'get_variation_id' ) ) ? $product->get_variation_id() : 0 );
|
||||
$this->set_variation( is_callable( array( $product, 'get_variation_attributes' ) ) ? $product->get_variation_attributes() : array() );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -174,10 +174,10 @@ class WC_Post_Data {
|
|||
* @param mixed $_meta_value
|
||||
*/
|
||||
public static function sync_product_stock_status( $meta_id, $object_id, $meta_key, $_meta_value ) {
|
||||
if ( '_stock' === $meta_key && 'product_variation' === get_post_type( $object_id ) ) {
|
||||
/*if ( '_stock' === $meta_key && 'product_variation' === get_post_type( $object_id ) && $_meta_value !== get_post_meta( $object_id, $meta_key, true ) ) {
|
||||
$product = wc_get_product( $object_id );
|
||||
$product->check_stock_status();
|
||||
}
|
||||
$product->check_stock_status(); @todo check_stock_status does save() which can cause redirect loop. Needed?
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,7 +99,7 @@ class WC_Product_Factory {
|
|||
} elseif ( is_numeric( $the_product ) ) {
|
||||
$the_product = get_post( $the_product );
|
||||
} elseif ( $the_product instanceof WC_Product ) {
|
||||
$the_product = get_post( $the_product->id );
|
||||
$the_product = get_post( $the_product->get_id() );
|
||||
} elseif ( ! ( $the_product instanceof WP_Post ) ) {
|
||||
$the_product = false;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ class WC_Product_Simple extends WC_Product {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sync grouped products with the children lowest price (so they can be sorted by price accurately).
|
||||
* Sync grouped products with the children lowest price (so they can be sorted by price accurately). @todo should this be here?
|
||||
*/
|
||||
public function grouped_product_sync() {
|
||||
if ( ! $this->get_parent_id() ) return;
|
||||
|
|
|
@ -282,7 +282,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
$available_variations = array();
|
||||
|
||||
foreach ( $this->get_children() as $child_id ) {
|
||||
$variation = $this->get_child( $child_id );
|
||||
$variation = wc_get_product( $child_id );
|
||||
|
||||
// Hide out of stock variations if 'Hide out of stock items from the catalog' is checked
|
||||
if ( empty( $variation->get_variation_id() ) || ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && ! $variation->is_in_stock() ) ) {
|
||||
|
@ -308,7 +308,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
*/
|
||||
public function get_available_variation( $variation ) {
|
||||
if ( is_numeric( $variation ) ) {
|
||||
$variation = $this->get_child( $variation );
|
||||
$variation = wc_get_product( $variation );
|
||||
}
|
||||
|
||||
if ( has_post_thumbnail( $variation->get_variation_id() ) ) {
|
||||
|
@ -336,8 +336,8 @@ class WC_Product_Variable extends WC_Product {
|
|||
'variation_is_visible' => $variation->variation_is_visible(),
|
||||
'variation_is_active' => $variation->variation_is_active(),
|
||||
'is_purchasable' => $variation->is_purchasable(),
|
||||
'display_price' => $variation->get_display_price(),
|
||||
'display_regular_price' => $variation->get_display_price( $variation->get_regular_price() ),
|
||||
'display_price' => wc_get_price_to_display( $variation ),
|
||||
'display_regular_price' => wc_get_price_to_display( $variation, array( 'price' => $variation->get_regular_price() ) ),
|
||||
'attributes' => $variation->get_variation_attributes(),
|
||||
'image_src' => $image,
|
||||
'image_link' => $image_link,
|
||||
|
@ -358,7 +358,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
'is_downloadable' => $variation->is_downloadable(),
|
||||
'is_virtual' => $variation->is_virtual(),
|
||||
'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no',
|
||||
'variation_description' => $variation->get_variation_description(),
|
||||
'variation_description' => $variation->get_description(),
|
||||
), $this, $variation );
|
||||
}
|
||||
|
||||
|
@ -443,7 +443,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sync variable product stock status with children.
|
||||
* Sync variable product stock status with children. @todo code here needs to be called or ran when woocommerce_variation_set_stock_status action fires. I have rmeoved the call from the variation class here.
|
||||
* @param int $product_id
|
||||
*/
|
||||
public static function sync_stock_status( $product_id ) {
|
||||
|
@ -517,7 +517,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
}
|
||||
|
||||
/**
|
||||
* Does a child have a weight set?
|
||||
* Does a child have a weight set? @todo
|
||||
* @since 2.7.0
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -526,7 +526,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
}
|
||||
|
||||
/**
|
||||
* Does a child have dimensions set?
|
||||
* Does a child have dimensions set? @todo
|
||||
* @since 2.7.0
|
||||
* @return boolean
|
||||
*/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -521,8 +521,10 @@ class WC_Tax {
|
|||
*/
|
||||
public static function get_shipping_tax_rates( $tax_class = null ) {
|
||||
// See if we have an explicitly set shipping tax class
|
||||
if ( $shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' ) ) {
|
||||
$tax_class = 'standard' === $shipping_tax_class ? '' : $shipping_tax_class;
|
||||
$shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
|
||||
|
||||
if ( 'inherit' !== $shipping_tax_class ) {
|
||||
$tax_class = $shipping_tax_class;
|
||||
}
|
||||
|
||||
$location = self::get_tax_location( $tax_class );
|
||||
|
|
|
@ -695,7 +695,7 @@ class WC_CLI_Order extends WC_CLI_Command {
|
|||
|
||||
// Check if the product exists.
|
||||
if ( is_object( $product ) ) {
|
||||
$product_id = ( isset( $product->variation_id ) ) ? $product->variation_id : $product->id;
|
||||
$product_id = ( isset( $product->variation_id ) ) ? $product->variation_id : $product->get_id();
|
||||
$product_sku = $product->get_sku();
|
||||
}
|
||||
|
||||
|
|
|
@ -772,7 +772,7 @@ class WC_CLI_Product extends WC_CLI_Command {
|
|||
// Add data that applies to every product type.
|
||||
$product_data = array(
|
||||
'title' => $product->get_title(),
|
||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->id,
|
||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->get_id(),
|
||||
'created_at' => $this->format_datetime( $product->get_post_data()->post_date_gmt ),
|
||||
'updated_at' => $this->format_datetime( $product->get_post_data()->post_modified_gmt ),
|
||||
'type' => $product->product_type,
|
||||
|
@ -821,17 +821,17 @@ class WC_CLI_Product extends WC_CLI_Command {
|
|||
'upsell_ids' => implode( ', ', $product->get_upsells() ),
|
||||
'cross_sell_ids' => implode( ', ', $product->get_cross_sells() ),
|
||||
'parent_id' => $product->post->post_parent,
|
||||
'categories' => implode( ', ', wp_get_post_terms( $product->id, 'product_cat', array( 'fields' => 'names' ) ) ),
|
||||
'tags' => implode( ', ', wp_get_post_terms( $product->id, 'product_tag', array( 'fields' => 'names' ) ) ),
|
||||
'categories' => implode( ', ', wp_get_post_terms( $product->get_id(), 'product_cat', array( 'fields' => 'names' ) ) ),
|
||||
'tags' => implode( ', ', wp_get_post_terms( $product->get_id(), 'product_tag', array( 'fields' => 'names' ) ) ),
|
||||
'images' => $this->get_images( $product ),
|
||||
'featured_src' => wp_get_attachment_url( get_post_thumbnail_id( $product->is_type( 'variation' ) ? $product->variation_id : $product->id ) ),
|
||||
'featured_src' => wp_get_attachment_url( get_post_thumbnail_id( $product->is_type( 'variation' ) ? $product->variation_id : $product->get_id() ) ),
|
||||
'attributes' => $this->get_attributes( $product ),
|
||||
'downloads' => $this->get_downloads( $product ),
|
||||
'download_limit' => (int) $product->download_limit,
|
||||
'download_expiry' => (int) $product->download_expiry,
|
||||
'download_type' => $product->download_type,
|
||||
'purchase_note' => wpautop( do_shortcode( wp_kses_post( $product->purchase_note ) ) ),
|
||||
'total_sales' => metadata_exists( 'post', $product->id, 'total_sales' ) ? (int) get_post_meta( $product->id, 'total_sales', true ) : 0,
|
||||
'total_sales' => metadata_exists( 'post', $product->get_id(), 'total_sales' ) ? (int) get_post_meta( $product->get_id(), 'total_sales', true ) : 0,
|
||||
'variations' => array(),
|
||||
'parent' => array(),
|
||||
);
|
||||
|
@ -867,20 +867,20 @@ class WC_CLI_Product extends WC_CLI_Command {
|
|||
// Add variation image if set
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_variation_id() );
|
||||
|
||||
} elseif ( has_post_thumbnail( $product->id ) ) {
|
||||
} elseif ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
|
||||
// Otherwise use the parent product featured image if set
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->id );
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_id() );
|
||||
}
|
||||
} else {
|
||||
|
||||
// Add featured image
|
||||
if ( has_post_thumbnail( $product->id ) ) {
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->id );
|
||||
if ( has_post_thumbnail( $product->get_id() ) ) {
|
||||
$attachment_ids[] = get_post_thumbnail_id( $product->get_id() );
|
||||
}
|
||||
|
||||
// Add gallery images
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_attachment_ids() );
|
||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() );
|
||||
}
|
||||
|
||||
// Build image data
|
||||
|
|
|
@ -23,6 +23,7 @@ include( 'wc-formatting-functions.php' );
|
|||
include( 'wc-order-functions.php' );
|
||||
include( 'wc-page-functions.php' );
|
||||
include( 'wc-product-functions.php' );
|
||||
include( 'wc-stock-functions.php' );
|
||||
include( 'wc-account-functions.php' );
|
||||
include( 'wc-term-functions.php' );
|
||||
include( 'wc-attribute-functions.php' );
|
||||
|
|
|
@ -510,6 +510,10 @@ global $wc_map_deprecated_filters;
|
|||
$wc_map_deprecated_filters = array(
|
||||
'woocommerce_add_to_cart_fragments' => 'add_to_cart_fragments',
|
||||
'woocommerce_add_to_cart_redirect' => 'add_to_cart_redirect',
|
||||
'woocommerce_product_get_width' => 'woocommerce_product_width',
|
||||
'woocommerce_product_get_height' => 'woocommerce_product_height',
|
||||
'woocommerce_product_get_length' => 'woocommerce_product_length',
|
||||
'woocommerce_product_get_weight' => 'woocommerce_product_weight',
|
||||
);
|
||||
|
||||
foreach ( $wc_map_deprecated_filters as $new => $old ) {
|
||||
|
|
|
@ -24,6 +24,19 @@ function wc_string_to_bool( $string ) {
|
|||
return is_bool( $string ) ? $string : ( 'yes' === $string || 1 === $string || '1' === $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a bool to a string.
|
||||
* @since 2.7.0
|
||||
* @param bool $bool
|
||||
* @return string yes or no
|
||||
*/
|
||||
function wc_bool_to_string( $bool ) {
|
||||
if ( ! is_bool( $bool ) ) {
|
||||
$bool = wc_string_to_bool( $bool );
|
||||
}
|
||||
return true === $bool ? 'yes' : 'no';
|
||||
}
|
||||
|
||||
/**
|
||||
* Explode a string into an array by $delimiter and remove empty values.
|
||||
* @since 2.7.0
|
||||
|
|
|
@ -665,44 +665,6 @@ function wc_get_order_item_meta( $item_id, $key, $single = true ) {
|
|||
return get_metadata( 'order_item', $item_id, $key, $single );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel all unpaid orders after held duration to prevent stock lock for those products.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function wc_cancel_unpaid_orders() {
|
||||
global $wpdb;
|
||||
|
||||
$held_duration = get_option( 'woocommerce_hold_stock_minutes' );
|
||||
|
||||
if ( $held_duration < 1 || get_option( 'woocommerce_manage_stock' ) != 'yes' )
|
||||
return;
|
||||
|
||||
$date = date( "Y-m-d H:i:s", strtotime( '-' . absint( $held_duration ) . ' MINUTES', current_time( 'timestamp' ) ) );
|
||||
|
||||
$unpaid_orders = $wpdb->get_col( $wpdb->prepare( "
|
||||
SELECT posts.ID
|
||||
FROM {$wpdb->posts} AS posts
|
||||
WHERE posts.post_type IN ('" . implode( "','", wc_get_order_types() ) . "')
|
||||
AND posts.post_status = 'wc-pending'
|
||||
AND posts.post_modified < %s
|
||||
", $date ) );
|
||||
|
||||
if ( $unpaid_orders ) {
|
||||
foreach ( $unpaid_orders as $unpaid_order ) {
|
||||
$order = wc_get_order( $unpaid_order );
|
||||
|
||||
if ( apply_filters( 'woocommerce_cancel_unpaid_order', 'checkout' === get_post_meta( $unpaid_order, '_created_via', true ), $order ) ) {
|
||||
$order->update_status( 'cancelled', __( 'Unpaid order cancelled - time limit reached.', 'woocommerce' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
|
||||
wp_schedule_single_event( time() + ( absint( $held_duration ) * 60 ), 'woocommerce_cancel_unpaid_orders' );
|
||||
}
|
||||
add_action( 'woocommerce_cancel_unpaid_orders', 'wc_cancel_unpaid_orders' );
|
||||
|
||||
/**
|
||||
* Return the count of processing orders.
|
||||
*
|
||||
|
@ -1110,45 +1072,40 @@ add_action( 'woocommerce_order_status_on-hold', 'wc_update_total_sales_counts' )
|
|||
add_action( 'woocommerce_order_status_cancelled', 'wc_update_total_sales_counts' );
|
||||
|
||||
/**
|
||||
* When a payment is complete, we can reduce stock levels for items within an order.
|
||||
* @since 2.7.0
|
||||
* @param int $order_id
|
||||
* Cancel all unpaid orders after held duration to prevent stock lock for those products.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function wc_maybe_reduce_stock_levels( $order_id ) {
|
||||
if ( apply_filters( 'woocommerce_payment_complete_reduce_order_stock', ! get_post_meta( $order_id, '_order_stock_reduced', true ), $order_id ) ) {
|
||||
wc_reduce_stock_levels( $order_id );
|
||||
add_post_meta( $order_id, '_order_stock_reduced', '1', true );
|
||||
function wc_cancel_unpaid_orders() {
|
||||
global $wpdb;
|
||||
|
||||
$held_duration = get_option( 'woocommerce_hold_stock_minutes' );
|
||||
|
||||
if ( $held_duration < 1 || 'yes' !== get_option( 'woocommerce_manage_stock' ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
add_action( 'woocommerce_payment_complete', 'wc_maybe_reduce_stock_levels' );
|
||||
|
||||
/**
|
||||
* Reduce stock levels for items within an order.
|
||||
* @since 2.7.0
|
||||
* @param int $order_id
|
||||
*/
|
||||
function wc_reduce_stock_levels( $order_id ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
$date = date( "Y-m-d H:i:s", strtotime( '-' . absint( $held_duration ) . ' MINUTES', current_time( 'timestamp' ) ) );
|
||||
|
||||
if ( 'yes' === get_option( 'woocommerce_manage_stock' ) && $order && apply_filters( 'woocommerce_can_reduce_order_stock', true, $order ) && sizeof( $order->get_items() ) > 0 ) {
|
||||
foreach ( $order->get_items() as $item ) {
|
||||
if ( $item->is_type( 'line_item' ) && ( $product = $item->get_product() ) && $product->managing_stock() ) {
|
||||
$qty = apply_filters( 'woocommerce_order_item_quantity', $item->get_quantity(), $order, $item );
|
||||
$new_stock = $product->reduce_stock( $qty );
|
||||
$item_name = $product->get_sku() ? $product->get_sku(): $item['product_id'];
|
||||
$unpaid_orders = $wpdb->get_col( $wpdb->prepare( "
|
||||
SELECT posts.ID
|
||||
FROM {$wpdb->posts} AS posts
|
||||
WHERE posts.post_type IN ('" . implode( "','", wc_get_order_types() ) . "')
|
||||
AND posts.post_status = 'wc-pending'
|
||||
AND posts.post_modified < %s
|
||||
", $date ) );
|
||||
|
||||
if ( ! empty( $item['variation_id'] ) ) {
|
||||
$order->add_order_note( sprintf( __( 'Item %1$s variation #%2$s stock reduced from %3$s to %4$s.', 'woocommerce' ), $item_name, $item['variation_id'], $new_stock + $qty, $new_stock ) );
|
||||
} else {
|
||||
$order->add_order_note( sprintf( __( 'Item %1$s stock reduced from %2$s to %3$s.', 'woocommerce' ), $item_name, $new_stock + $qty, $new_stock ) );
|
||||
}
|
||||
if ( $unpaid_orders ) {
|
||||
foreach ( $unpaid_orders as $unpaid_order ) {
|
||||
$order = wc_get_order( $unpaid_order );
|
||||
|
||||
if ( $new_stock < 0 ) {
|
||||
do_action( 'woocommerce_product_on_backorder', array( 'product' => $product, 'order_id' => $order_id, 'quantity' => $qty_ordered ) );
|
||||
}
|
||||
if ( apply_filters( 'woocommerce_cancel_unpaid_order', 'checkout' === get_post_meta( $unpaid_order, '_created_via', true ), $order ) ) {
|
||||
$order->update_status( 'cancelled', __( 'Unpaid order cancelled - time limit reached.', 'woocommerce' ) );
|
||||
}
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_reduce_order_stock', $order );
|
||||
}
|
||||
|
||||
wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
|
||||
wp_schedule_single_event( time() + ( absint( $held_duration ) * 60 ), 'woocommerce_cancel_unpaid_orders' );
|
||||
}
|
||||
add_action( 'woocommerce_cancel_unpaid_orders', 'wc_cancel_unpaid_orders' );
|
||||
|
|
|
@ -83,22 +83,24 @@ function wc_get_products( $args ) {
|
|||
* Generate WP_Query args.
|
||||
*/
|
||||
$wp_query_args = array(
|
||||
'post_type' => array( 'product', 'product_variation' ),
|
||||
'post_type' => 'variation' === $args['type'] ? 'product_variation' : 'product',
|
||||
'post_status' => $args['status'],
|
||||
'posts_per_page' => $args['limit'],
|
||||
'meta_query' => array(),
|
||||
'fields' => 'ids',
|
||||
'orderby' => $args['orderby'],
|
||||
'order' => $args['order'],
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'product_type',
|
||||
'field' => 'slug',
|
||||
'terms' => $args['type'],
|
||||
)
|
||||
)
|
||||
'tax_query' => array(),
|
||||
);
|
||||
|
||||
if ( 'variation' !== $args['type'] ) {
|
||||
$wp_query_args['tax_query'][] = array(
|
||||
'taxonomy' => 'product_type',
|
||||
'field' => 'slug',
|
||||
'terms' => $args['type'],
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $args['sku'] ) ) {
|
||||
$wp_query_args['meta_query'][] = array(
|
||||
'key' => '_sku',
|
||||
|
@ -178,33 +180,6 @@ function wc_get_product( $the_product = false, $args = array() ) {
|
|||
return WC()->product_factory->get_product( $the_product, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a product's stock amount.
|
||||
*
|
||||
* @param int $product_id
|
||||
* @param int $new_stock_level
|
||||
*/
|
||||
function wc_update_product_stock( $product_id, $new_stock_level ) {
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
if ( ! metadata_exists( 'post', $product_id, '_stock' ) || $product->get_stock_quantity() !== $new_stock_level ) {
|
||||
$product->set_stock( $new_stock_level );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a product's stock status.
|
||||
*
|
||||
* @param int $product_id
|
||||
* @param int $status
|
||||
*/
|
||||
function wc_update_product_stock_status( $product_id, $status ) {
|
||||
$product = wc_get_product( $product_id );
|
||||
if ( $product ) {
|
||||
$product->set_stock_status( $status );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not SKUS are enabled.
|
||||
* @return bool
|
||||
|
@ -899,6 +874,52 @@ function wc_get_product_visibility_options() {
|
|||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product tax class options.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @return array
|
||||
*/
|
||||
function wc_get_product_tax_class_options() {
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
$tax_class_options = array();
|
||||
$tax_class_options[''] = __( 'Standard', 'woocommerce' );
|
||||
|
||||
if ( ! empty( $tax_classes ) ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$tax_class_options[ sanitize_title( $class ) ] = $class;
|
||||
}
|
||||
}
|
||||
return $tax_class_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stock status options.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @return array
|
||||
*/
|
||||
function wc_get_product_stock_status_options() {
|
||||
return array(
|
||||
'instock' => __( 'In stock', 'woocommerce' ),
|
||||
'outofstock' => __( 'Out of stock', 'woocommerce' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backorder options.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @return array
|
||||
*/
|
||||
function wc_get_product_backorder_options() {
|
||||
return array(
|
||||
'no' => __( 'Do not allow', 'woocommerce' ),
|
||||
'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
|
||||
'yes' => __( 'Allow', 'woocommerce' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related products based on product category and tags.
|
||||
*
|
||||
|
@ -1038,7 +1059,7 @@ function wc_get_price_including_tax( $product, $args = array() ) {
|
|||
$price = round( $price * $qty + $tax_amount, wc_get_price_decimals() );
|
||||
} else {
|
||||
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
|
||||
$base_tax_rates = WC_Tax::get_base_tax_rates( $product->tax_class );
|
||||
$base_tax_rates = WC_Tax::get_base_tax_rates( $product->get_tax_class( true ) );
|
||||
|
||||
if ( ! empty( WC()->customer ) && WC()->customer->get_is_vat_exempt() ) {
|
||||
$base_taxes = WC_Tax::calc_tax( $price * $qty, $base_tax_rates, true );
|
||||
|
@ -1079,7 +1100,7 @@ function wc_get_price_excluding_tax( $product, $args = array() ) {
|
|||
$qty = $args['qty'];
|
||||
|
||||
if ( $product->is_taxable() && wc_prices_include_tax() ) {
|
||||
$tax_rates = WC_Tax::get_base_tax_rates( $product->tax_class );
|
||||
$tax_rates = WC_Tax::get_base_tax_rates( $product->get_tax_class( true ) );
|
||||
$taxes = WC_Tax::calc_tax( $price * $qty, $tax_rates, true );
|
||||
$price = WC_Tax::round( $price * $qty - array_sum( $taxes ) );
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce Stock Functions
|
||||
*
|
||||
* Functions used to manage product stock levels.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Core
|
||||
* @package WooCommerce/Functions
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a product's stock amount.
|
||||
*
|
||||
* Uses queries rather than update_post_meta so we can do this in one query (to avoid stock issues).
|
||||
*
|
||||
* @since 2.7.0 this supports set, increase and decrease.
|
||||
* @param int|WC_Product $product
|
||||
* @param int|null $stock_quantity
|
||||
* @param string $operation set, add, or subtract
|
||||
*/
|
||||
function wc_update_product_stock( $product, $stock_quantity = null, $operation = 'set' ) {
|
||||
if ( ! is_null( $stock_quantity ) ) {
|
||||
// Find product that needs a stock reduction.
|
||||
$product = wc_get_product( $product );
|
||||
|
||||
if ( ! $product->managing_stock() && $product->get_parent_id() ) {
|
||||
$product = wc_get_product( $product->get_parent_id() );
|
||||
}
|
||||
|
||||
if ( ! $product->managing_stock() ) {
|
||||
return new WP_Error( 'error', __( 'Product is not stock managed', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
// Ensure key exists
|
||||
add_post_meta( $product->get_id(), '_stock', 0, true );
|
||||
|
||||
// Update stock in DB directly
|
||||
switch ( $operation ) {
|
||||
case 'add' :
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = meta_value + %f WHERE post_id = %d AND meta_key='_stock'", $stock_quantity, $product->get_id() ) );
|
||||
break;
|
||||
case 'subtract' :
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = meta_value - %f WHERE post_id = %d AND meta_key='_stock'", $stock_quantity, $product->get_id() ) );
|
||||
break;
|
||||
default :
|
||||
if ( $product->get_stock_quantity() !== $stock_quantity ) {
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %f WHERE post_id = %d AND meta_key='_stock'", $stock_quantity, $product->get_id() ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
wp_cache_delete( $product->get_id(), 'post_meta' );
|
||||
delete_transient( 'wc_low_stock_count' );
|
||||
delete_transient( 'wc_outofstock_count' );
|
||||
|
||||
// Re-read product data.
|
||||
$product->read( $product->get_id() );
|
||||
|
||||
// Check stock status.
|
||||
wc_check_product_stock_status( $product );
|
||||
|
||||
// Actions
|
||||
do_action( $product->is_type( 'variation' ) ? 'woocommerce_variation_set_stock' : 'woocommerce_product_set_stock', $product );
|
||||
}
|
||||
|
||||
return $product->get_stock_quantity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stock status needs changing.
|
||||
* @since 2.7.0
|
||||
* @param int|WC_Product $product
|
||||
*/
|
||||
function wc_check_product_stock_status( $product ) {
|
||||
$product = wc_get_product( $product );
|
||||
|
||||
if ( $product->managing_stock() ) {
|
||||
if ( $product->backorders_allowed() && 'instock' !== $product->get_stock_status() ) {
|
||||
$product->set_stock_status( 'instock' );
|
||||
|
||||
} elseif ( $product->get_stock_quantity() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) {
|
||||
$product->set_stock_status( 'outofstock' );
|
||||
|
||||
} elseif ( $product->get_stock_quantity() > get_option( 'woocommerce_notify_no_stock_amount' ) ) {
|
||||
$product->set_stock_status( 'instock' );
|
||||
}
|
||||
}
|
||||
|
||||
$product->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a product's stock status.
|
||||
*
|
||||
* @param int $product_id
|
||||
* @param int $status
|
||||
*/
|
||||
function wc_update_product_stock_status( $product_id, $status ) {
|
||||
$product = wc_get_product( $product_id );
|
||||
if ( $product ) {
|
||||
$product->set_stock_status( $status );
|
||||
//$product->save(); @todo causes timeout in class-wc-post-data.php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When a payment is complete, we can reduce stock levels for items within an order.
|
||||
* @since 2.7.0
|
||||
* @param int $order_id
|
||||
*/
|
||||
function wc_maybe_reduce_stock_levels( $order_id ) {
|
||||
if ( apply_filters( 'woocommerce_payment_complete_reduce_order_stock', ! get_post_meta( $order_id, '_order_stock_reduced', true ), $order_id ) ) {
|
||||
wc_reduce_stock_levels( $order_id );
|
||||
add_post_meta( $order_id, '_order_stock_reduced', '1', true );
|
||||
}
|
||||
}
|
||||
add_action( 'woocommerce_payment_complete', 'wc_maybe_reduce_stock_levels' );
|
||||
|
||||
/**
|
||||
* Reduce stock levels for items within an order.
|
||||
* @since 2.7.0
|
||||
* @param int $order_id
|
||||
*/
|
||||
function wc_reduce_stock_levels( $order_id ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( 'yes' === get_option( 'woocommerce_manage_stock' ) && $order && apply_filters( 'woocommerce_can_reduce_order_stock', true, $order ) && sizeof( $order->get_items() ) > 0 ) {
|
||||
foreach ( $order->get_items() as $item ) {
|
||||
if ( $item->is_type( 'line_item' ) && ( $product = $item->get_product() ) && $product->managing_stock() ) {
|
||||
$qty = apply_filters( 'woocommerce_order_item_quantity', $item->get_quantity(), $order, $item );
|
||||
$item_name = $product->get_formatted_name();
|
||||
$new_stock = wc_update_product_stock( $product, $qty, 'subtract' );
|
||||
|
||||
if ( ! is_wp_error( $new_stock ) ) {
|
||||
$order->add_order_note( sprintf( __( '%1$s stock reduced from %2$s to %3$s.', 'woocommerce' ), $item_name, $new_stock + $qty, $new_stock ) );
|
||||
|
||||
if ( '' !== get_option( 'woocommerce_notify_no_stock_amount' ) && $new_stock <= get_option( 'woocommerce_notify_no_stock_amount' ) ) {
|
||||
do_action( 'woocommerce_no_stock', $product );
|
||||
} elseif ( '' !== get_option( 'woocommerce_notify_low_stock_amount' ) && $new_stock <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
|
||||
do_action( 'woocommerce_low_stock', $product );
|
||||
}
|
||||
|
||||
if ( $new_stock < 0 ) {
|
||||
do_action( 'woocommerce_product_on_backorder', array( 'product' => $product, 'order_id' => $order_id, 'quantity' => $qty_ordered ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_reduce_order_stock', $order );
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ function wc_template_redirect() {
|
|||
$product = wc_get_product( $wp_query->post );
|
||||
|
||||
if ( $product && $product->is_visible() ) {
|
||||
wp_safe_redirect( get_permalink( $product->id ), 302 );
|
||||
wp_safe_redirect( get_permalink( $product->get_id() ), 302 );
|
||||
exit;
|
||||
}
|
||||
} elseif ( is_add_payment_method_page() ) {
|
||||
|
@ -303,7 +303,7 @@ function wc_product_post_class( $classes, $class = '', $post_id = '' ) {
|
|||
|
||||
if ( $product ) {
|
||||
$classes[] = wc_get_loop_class();
|
||||
$classes[] = $product->stock_status;
|
||||
$classes[] = $product->get_stock_status();
|
||||
|
||||
if ( $product->is_on_sale() ) {
|
||||
$classes[] = 'sale';
|
||||
|
@ -979,7 +979,7 @@ if ( ! function_exists( 'woocommerce_template_single_add_to_cart' ) ) {
|
|||
*/
|
||||
function woocommerce_template_single_add_to_cart() {
|
||||
global $product;
|
||||
do_action( 'woocommerce_' . $product->product_type . '_add_to_cart' );
|
||||
do_action( 'woocommerce_' . $product->get_type() . '_add_to_cart' );
|
||||
}
|
||||
}
|
||||
if ( ! function_exists( 'woocommerce_simple_add_to_cart' ) ) {
|
||||
|
@ -1030,7 +1030,7 @@ if ( ! function_exists( 'woocommerce_variable_add_to_cart' ) ) {
|
|||
wc_get_template( 'single-product/add-to-cart/variable.php', array(
|
||||
'available_variations' => $get_variations ? $product->get_available_variations() : false,
|
||||
'attributes' => $product->get_variation_attributes(),
|
||||
'selected_attributes' => $product->get_variation_default_attributes(),
|
||||
'selected_attributes' => $product->get_default_attributes(),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
@ -2171,7 +2171,7 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
|
|||
if ( ! empty( $options ) ) {
|
||||
if ( $product && taxonomy_exists( $attribute ) ) {
|
||||
// Get terms if this is a taxonomy - ordered. We need the names too.
|
||||
$terms = wc_get_product_terms( $product->id, $attribute, array( 'fields' => 'all' ) );
|
||||
$terms = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );
|
||||
|
||||
foreach ( $terms as $term ) {
|
||||
if ( in_array( $term->slug, $options ) ) {
|
||||
|
|
|
@ -1018,3 +1018,12 @@ function wc_update_270_grouped_products() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function wc_update_270_settings() {
|
||||
$woocommerce_shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
|
||||
if ( '' === $woocommerce_shipping_tax_class ) {
|
||||
update_option( 'woocommerce_shipping_tax_class', 'inherit' );
|
||||
} elseif ( 'standard' === $woocommerce_shipping_tax_class ) {
|
||||
update_option( 'woocommerce_shipping_tax_class', '' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -420,7 +420,7 @@ function wc_get_customer_available_downloads( $customer_id ) {
|
|||
|
||||
$product_id = intval( $result->product_id );
|
||||
|
||||
if ( ! $_product || $_product->id != $product_id ) {
|
||||
if ( ! $_product || $_product->get_id() != $product_id ) {
|
||||
// new product
|
||||
$file_number = 0;
|
||||
$_product = wc_get_product( $product_id );
|
||||
|
@ -453,7 +453,7 @@ function wc_get_customer_available_downloads( $customer_id ) {
|
|||
home_url( '/' )
|
||||
),
|
||||
'download_id' => $result->download_id,
|
||||
'product_id' => $_product->id,
|
||||
'product_id' => $_product->get_id(),
|
||||
'product_name' => $_product->get_title(),
|
||||
'download_name' => $download_name,
|
||||
'order_id' => $order->get_id(),
|
||||
|
|
|
@ -24,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
global $product; ?>
|
||||
|
||||
<li>
|
||||
<a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">
|
||||
<a href="<?php echo esc_url( $product->get_permalink() ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">
|
||||
<?php echo $product->get_image(); ?>
|
||||
<span class="product-title"><?php echo $product->get_title(); ?></span>
|
||||
</a>
|
||||
|
|
|
@ -59,7 +59,7 @@ foreach ( $items as $item_id => $item ) :
|
|||
<?php
|
||||
}
|
||||
|
||||
if ( $show_purchase_note && is_object( $product ) && ( $purchase_note = get_post_meta( $product->id, '_purchase_note', true ) ) ) : ?>
|
||||
if ( $show_purchase_note && is_object( $product ) && ( $purchase_note = $product->get_purchase_note() ) ) : ?>
|
||||
<tr>
|
||||
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); ?></td>
|
||||
</tr>
|
||||
|
|
|
@ -51,7 +51,7 @@ foreach ( $items as $item_id => $item ) :
|
|||
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text );
|
||||
}
|
||||
// Note
|
||||
if ( $show_purchase_note && ( $purchase_note = get_post_meta( $product->id, '_purchase_note', true ) ) ) {
|
||||
if ( $show_purchase_note && is_object( $product ) && ( $purchase_note = $product->get_purchase_note() ) ) {
|
||||
echo "\n" . do_shortcode( wp_kses_post( $purchase_note ) );
|
||||
}
|
||||
echo "\n\n";
|
||||
|
|
|
@ -26,7 +26,7 @@ echo apply_filters( 'woocommerce_loop_add_to_cart_link',
|
|||
sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
|
||||
esc_url( $product->add_to_cart_url() ),
|
||||
esc_attr( isset( $quantity ) ? $quantity : 1 ),
|
||||
esc_attr( $product->id ),
|
||||
esc_attr( $product->get_id() ),
|
||||
esc_attr( $product->get_sku() ),
|
||||
esc_attr( isset( $class ) ? $class : 'button' ),
|
||||
esc_html( $product->add_to_cart_text() )
|
||||
|
|
|
@ -49,7 +49,7 @@ $show_customer_details = is_user_logged_in() && $order->get_user_id() === get_cu
|
|||
'item_id' => $item_id,
|
||||
'item' => $item,
|
||||
'show_purchase_note' => $show_purchase_note,
|
||||
'purchase_note' => $product ? get_post_meta( $product->id, '_purchase_note', true ) : '',
|
||||
'purchase_note' => $product ? $product->get_purchase_note() : '',
|
||||
'product' => $product,
|
||||
) );
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ if ( ! comments_open() ) {
|
|||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->id ) ) : ?>
|
||||
<?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) : ?>
|
||||
|
||||
<div id="review_form_wrapper">
|
||||
<div id="review_form">
|
||||
|
|
|
@ -85,7 +85,7 @@ do_action( 'woocommerce_before_add_to_cart_form' ); ?>
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
|
||||
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" />
|
||||
|
||||
<?php if ( $quantites_required ) : ?>
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ if ( $product->is_in_stock() ) : ?>
|
|||
}
|
||||
?>
|
||||
|
||||
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
|
||||
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" />
|
||||
|
||||
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ $attribute_keys = array_keys( $attributes );
|
|||
|
||||
do_action( 'woocommerce_before_add_to_cart_form' ); ?>
|
||||
|
||||
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->id ); ?>" data-product_variations="<?php echo htmlspecialchars( wp_json_encode( $available_variations ) ) ?>">
|
||||
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo htmlspecialchars( wp_json_encode( $available_variations ) ) ?>">
|
||||
<?php do_action( 'woocommerce_before_variations_form' ); ?>
|
||||
|
||||
<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
|
||||
|
|
|
@ -18,7 +18,7 @@ global $product;
|
|||
<?php woocommerce_quantity_input( array( 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1 ) ); ?>
|
||||
<?php endif; ?>
|
||||
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
|
||||
<input type="hidden" name="add-to-cart" value="<?php echo absint( $product->id ); ?>" />
|
||||
<input type="hidden" name="product_id" value="<?php echo absint( $product->id ); ?>" />
|
||||
<input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
|
||||
<input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
|
||||
<input type="hidden" name="variation_id" class="variation_id" value="0" />
|
||||
</div>
|
||||
|
|
|
@ -27,7 +27,7 @@ global $product;
|
|||
|
||||
<p class="price"><?php echo $product->get_price_html(); ?></p>
|
||||
|
||||
<meta itemprop="price" content="<?php echo esc_attr( $product->get_display_price() ); ?>" />
|
||||
<meta itemprop="price" content="<?php echo esc_attr( wc_get_price_to_display( $product ) ); ?>" />
|
||||
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" />
|
||||
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ ob_start();
|
|||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $product->has_dimensions() || get_post_meta( $product->id, '_child_has_dimensions', true ) ) : $has_row = true; ?>
|
||||
<?php if ( $product->has_dimensions() || $product->child_has_dimensions() ) : $has_row = true; ?>
|
||||
<tr class="<?php if ( ( $alt = $alt * -1 ) === 1 ) echo 'alt'; ?>">
|
||||
<th><?php _e( 'Dimensions', 'woocommerce' ) ?></th>
|
||||
<td class="product_dimensions"><?php echo $product->get_dimensions() ? $product->get_dimensions() : __( 'N/A', 'woocommerce' ); ?></td>
|
||||
|
@ -61,7 +61,7 @@ ob_start();
|
|||
<td><?php
|
||||
if ( $attribute['is_taxonomy'] ) {
|
||||
|
||||
$values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
|
||||
$values = wc_get_product_terms( $product->get_id(), $attribute['name'], array( 'fields' => 'names' ) );
|
||||
echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
|
||||
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,7 @@ global $post, $product;
|
|||
<div class="images">
|
||||
<?php
|
||||
if ( has_post_thumbnail() ) {
|
||||
$attachment_count = count( $product->get_gallery_attachment_ids() );
|
||||
$attachment_count = count( $product->get_gallery_image_ids() );
|
||||
$gallery = $attachment_count > 0 ? '[product-gallery]' : '';
|
||||
$props = wc_get_product_attachment_props( get_post_thumbnail_id(), $post );
|
||||
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
|
||||
|
|
|
@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
global $post, $product, $woocommerce;
|
||||
|
||||
$attachment_ids = $product->get_gallery_attachment_ids();
|
||||
$attachment_ids = $product->get_gallery_image_ids();
|
||||
|
||||
if ( $attachment_ids ) {
|
||||
$loop = 0;
|
||||
|
|
|
@ -30,6 +30,6 @@ if ( ! $product->is_in_stock() ) : ?>
|
|||
|
||||
<?php elseif ( $product->managing_stock() ) : ?>
|
||||
|
||||
<p class="stock in-stock"><?php echo wp_kses_post( wc_format_stock_for_display( $product->get_total_stock(), $product->backorders_allowed() && $product->backorders_require_notification() ) ); ?></p>
|
||||
<p class="stock in-stock"><?php echo wp_kses_post( wc_format_stock_for_display( $product->get_stock_quantity(), $product->backorders_allowed() && $product->backorders_require_notification() ) ); ?></p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
|
|
@ -33,7 +33,7 @@ $args = array(
|
|||
'posts_per_page' => $posts_per_page,
|
||||
'orderby' => $orderby,
|
||||
'post__in' => $upsells,
|
||||
'post__not_in' => array( $product->id ),
|
||||
'post__not_in' => array( $product->get_id() ),
|
||||
'meta_query' => WC()->query->get_meta_query(),
|
||||
);
|
||||
|
||||
|
|
|
@ -40,10 +40,10 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_simple_product();
|
||||
// Create 10 products reviews for the product
|
||||
for ( $i = 0; $i < 10; $i++ ) {
|
||||
$review_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$review_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
}
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/reviews' ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/reviews' ) );
|
||||
$product_reviews = $response->get_data();
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
@ -59,17 +59,17 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
'_links' => array(
|
||||
'self' => array(
|
||||
array(
|
||||
'href' => rest_url( '/wc/v1/products/' . $product->id . '/reviews/' . $review_id ),
|
||||
'href' => rest_url( '/wc/v1/products/' . $product->get_id() . '/reviews/' . $review_id ),
|
||||
),
|
||||
),
|
||||
'collection' => array(
|
||||
array(
|
||||
'href' => rest_url( '/wc/v1/products/' . $product->id . '/reviews' ),
|
||||
'href' => rest_url( '/wc/v1/products/' . $product->get_id() . '/reviews' ),
|
||||
),
|
||||
),
|
||||
'up' => array(
|
||||
array(
|
||||
'href' => rest_url( '/wc/v1/products/' . $product->id ),
|
||||
'href' => rest_url( '/wc/v1/products/' . $product->get_id() ),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -84,7 +84,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_get_product_reviews_without_permission() {
|
||||
wp_set_current_user( 0 );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/reviews' ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/reviews' ) );
|
||||
$this->assertEquals( 401, $response->get_status() );
|
||||
}
|
||||
|
||||
|
@ -107,9 +107,9 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_get_product_review() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/reviews/' . $product_review_id ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/reviews/' . $product_review_id ) );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
@ -132,8 +132,8 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_get_product_review_without_permission() {
|
||||
wp_set_current_user( 0 );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/reviews/' . $product_review_id ) );
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/reviews/' . $product_review_id ) );
|
||||
$this->assertEquals( 401, $response->get_status() );
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_get_product_review_invalid_id() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/reviews/0' ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/reviews/0' ) );
|
||||
$this->assertEquals( 404, $response->get_status() );
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_create_product_review() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->id . '/reviews' );
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->get_id() . '/reviews' );
|
||||
$request->set_body_params( array(
|
||||
'review' => 'Hello world.',
|
||||
'name' => 'Admin',
|
||||
|
@ -189,7 +189,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
// missing review
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->id . '/reviews' );
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->get_id() . '/reviews' );
|
||||
$request->set_body_params( array(
|
||||
'name' => 'Admin',
|
||||
'email' => 'woo@woo.local',
|
||||
|
@ -200,7 +200,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEquals( 400, $response->get_status() );
|
||||
|
||||
// missing name
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->id . '/reviews' );
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->get_id() . '/reviews' );
|
||||
$request->set_body_params( array(
|
||||
'review' => 'Hello world.',
|
||||
'email' => 'woo@woo.local',
|
||||
|
@ -211,7 +211,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEquals( 400, $response->get_status() );
|
||||
|
||||
// missing email
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->id . '/reviews' );
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->get_id() . '/reviews' );
|
||||
$request->set_body_params( array(
|
||||
'review' => 'Hello world.',
|
||||
'name' => 'Admin',
|
||||
|
@ -230,16 +230,16 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_update_product_review() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/reviews/' . $product_review_id ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/reviews/' . $product_review_id ) );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 'Review content here', $data['review'] );
|
||||
$this->assertEquals( 'admin', $data['name'] );
|
||||
$this->assertEquals( 'woo@woo.local', $data['email'] );
|
||||
$this->assertEquals( 0, $data['rating'] );
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->id . '/reviews/' . $product_review_id );
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->get_id() . '/reviews/' . $product_review_id );
|
||||
$request->set_body_params( array(
|
||||
'review' => 'Hello world - updated.',
|
||||
'name' => 'Justin',
|
||||
|
@ -262,9 +262,9 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_update_product_review_without_permission() {
|
||||
wp_set_current_user( 0 );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->id . '/reviews/' . $product_review_id );
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->get_id() . '/reviews/' . $product_review_id );
|
||||
$request->set_body_params( array(
|
||||
'review' => 'Hello world.',
|
||||
'name' => 'Admin',
|
||||
|
@ -285,7 +285,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->id . '/reviews/0' );
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->get_id() . '/reviews/0' );
|
||||
$request->set_body_params( array(
|
||||
'review' => 'Hello world.',
|
||||
'name' => 'Admin',
|
||||
|
@ -305,9 +305,9 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_delete_product_review() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->id . '/reviews/' . $product_review_id );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->get_id() . '/reviews/' . $product_review_id );
|
||||
$request->set_param( 'force', true );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
@ -321,9 +321,9 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_delete_product_without_permission() {
|
||||
wp_set_current_user( 0 );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->id . '/reviews/' . $product_review_id );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->get_id() . '/reviews/' . $product_review_id );
|
||||
$response = $this->server->dispatch( $request );
|
||||
|
||||
$this->assertEquals( 401, $response->get_status() );
|
||||
|
@ -337,9 +337,9 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_delete_product_review_invalid_id() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$product_review_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->id . '/reviews/0' );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->get_id() . '/reviews/0' );
|
||||
$request->set_param( 'force', true );
|
||||
$response = $this->server->dispatch( $request );
|
||||
|
||||
|
@ -353,12 +353,12 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
$review_1_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$review_2_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$review_3_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$review_4_id = WC_Helper_Product::create_product_review( $product->id );
|
||||
$review_1_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
$review_2_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
$review_3_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
$review_4_id = WC_Helper_Product::create_product_review( $product->get_id() );
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->id . '/reviews/batch' );
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->get_id() . '/reviews/batch' );
|
||||
$request->set_body_params( array(
|
||||
'update' => array(
|
||||
array(
|
||||
|
@ -390,7 +390,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEquals( $review_2_id, $data['delete'][0]['id'] );
|
||||
$this->assertEquals( $review_3_id, $data['delete'][1]['id'] );
|
||||
|
||||
$request = new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/reviews' );
|
||||
$request = new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/reviews' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
|
@ -405,7 +405,7 @@ class Product_Reviews extends WC_REST_Unit_Test_Case {
|
|||
public function test_product_review_schema() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v1/products/' . $product->id . '/reviews' );
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v1/products/' . $product->get_id() . '/reviews' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
|
|
@ -39,7 +39,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
public function test_get_variations() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_variation_product();
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations' ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations' ) );
|
||||
$variations = $response->get_data();
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
@ -56,7 +56,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
public function test_get_variations_without_permission() {
|
||||
wp_set_current_user( 0 );
|
||||
$product = WC_Helper_Product::create_variation_product();
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations' ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations' ) );
|
||||
$this->assertEquals( 401, $response->get_status() );
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$children = $product->get_children();
|
||||
$variation_id = $children[0];
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations/' . $variation_id ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations/' . $variation_id ) );
|
||||
$variation = $response->get_data();
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
@ -89,7 +89,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_variation_product();
|
||||
$children = $product->get_children();
|
||||
$variation_id = $children[0];
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations/' . $variation_id ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations/' . $variation_id ) );
|
||||
$this->assertEquals( 401, $response->get_status() );
|
||||
}
|
||||
|
||||
|
@ -104,12 +104,12 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$children = $product->get_children();
|
||||
$variation_id = $children[0];
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->id . '/variations/' . $variation_id );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->get_id() . '/variations/' . $variation_id );
|
||||
$request->set_param( 'force', true );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations' ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations' ) );
|
||||
$variations = $response->get_data();
|
||||
$this->assertEquals( 1, count( $variations ) );
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$children = $product->get_children();
|
||||
$variation_id = $children[0];
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->id . '/variations/' . $variation_id );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->get_id() . '/variations/' . $variation_id );
|
||||
$request->set_param( 'force', true );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertEquals( 401, $response->get_status() );
|
||||
|
@ -139,7 +139,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
public function test_delete_variation_with_invalid_id() {
|
||||
wp_set_current_user( 0 );
|
||||
$product = WC_Helper_Product::create_variation_product();
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->id . '/variations/0' );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wc/v1/products/' . $product->get_id() . '/variations/0' );
|
||||
$request->set_param( 'force', true );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertEquals( 404, $response->get_status() );
|
||||
|
@ -156,7 +156,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$children = $product->get_children();
|
||||
$variation_id = $children[0];
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations/' . $variation_id ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations/' . $variation_id ) );
|
||||
$variation = $response->get_data();
|
||||
|
||||
$this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $variation['sku'] );
|
||||
|
@ -164,7 +164,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEmpty( $variation['sale_price'] );
|
||||
$this->assertEquals( 'small', $variation['attributes'][0]['option'] );
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->id . '/variations/' . $variation_id );
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->get_id() . '/variations/' . $variation_id );
|
||||
$request->set_body_params( array(
|
||||
'sku' => 'FIXED-SKU',
|
||||
'sale_price' => '8',
|
||||
|
@ -197,7 +197,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$children = $product->get_children();
|
||||
$variation_id = $children[0];
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->id . '/variations/' . $variation_id );
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->get_id() . '/variations/' . $variation_id );
|
||||
$request->set_body_params( array(
|
||||
'sku' => 'FIXED-SKU-NO-PERMISSION',
|
||||
) );
|
||||
|
@ -213,7 +213,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
public function test_update_variation_with_invalid_id() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_variation_product();
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->id . '/variations/0' );
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->get_id() . '/variations/0' );
|
||||
$request->set_body_params( array(
|
||||
'sku' => 'FIXED-SKU-NO-PERMISSION',
|
||||
) );
|
||||
|
@ -230,11 +230,11 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_variation_product();
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations' ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations' ) );
|
||||
$variations = $response->get_data();
|
||||
$this->assertEquals( 2, count( $variations ) );
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->id . '/variations' );
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->get_id() . '/variations' );
|
||||
$request->set_body_params( array(
|
||||
'sku' => 'DUMMY SKU VARIABLE MEDIUM',
|
||||
'regular_price' => '12',
|
||||
|
@ -251,7 +251,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $variation['sku'] );
|
||||
$this->assertEquals( 'medium', $variation['attributes'][0]['option'] );
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations' ) );
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations' ) );
|
||||
$variations = $response->get_data();
|
||||
$this->assertEquals( 3, count( $variations ) );
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
wp_set_current_user( 0 );
|
||||
$product = WC_Helper_Product::create_variation_product();
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->id . '/variations' );
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->get_id() . '/variations' );
|
||||
$request->set_body_params( array(
|
||||
'sku' => 'DUMMY SKU VARIABLE MEDIUM',
|
||||
'regular_price' => '12',
|
||||
|
@ -283,7 +283,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_variation_product();
|
||||
$children = $product->get_children();
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->id . '/variations/batch' );
|
||||
$request = new WP_REST_Request( 'POST', '/wc/v1/products/' . $product->get_id() . '/variations/batch' );
|
||||
$request->set_body_params( array(
|
||||
'update' => array(
|
||||
array(
|
||||
|
@ -314,7 +314,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEquals( 'medium', $data['create'][0]['attributes'][0]['option'] );
|
||||
$this->assertEquals( $children[1], $data['delete'][0]['id'] );
|
||||
|
||||
$request = new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->id . '/variations' );
|
||||
$request = new WP_REST_Request( 'GET', '/wc/v1/products/' . $product->get_id() . '/variations' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
|
@ -329,7 +329,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
public function test_variation_schema() {
|
||||
wp_set_current_user( $this->user );
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v1/products/' . $product->id . '/variations' );
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v1/products/' . $product->get_id() . '/variations' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
|
|
@ -186,7 +186,7 @@ class Products_API extends WC_REST_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( array( 'small' ), $data['attributes'][0]['options'] );
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->id );
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v1/products/' . $product->get_id() );
|
||||
$request->set_body_params( array(
|
||||
'attributes' => array(
|
||||
array( 'id' => 0, 'name' => 'pa_color', 'options' => array( 'red', 'yellow' ), 'visible' => false, 'variation' => 1 ),
|
||||
|
|
|
@ -34,19 +34,19 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
// Add product to cart x1, calc and test
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
WC()->cart->calculate_totals();
|
||||
$this->assertEquals( '9.00', number_format( WC()->cart->total, 2, '.', '' ) );
|
||||
$this->assertEquals( '1.00', number_format( WC()->cart->discount_cart, 2, '.', '' ) );
|
||||
|
||||
// Add product to cart x2, calc and test
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
WC()->cart->calculate_totals();
|
||||
$this->assertEquals( '19.00', number_format( WC()->cart->total, 2, '.', '' ) );
|
||||
$this->assertEquals( '1.00', number_format( WC()->cart->discount_cart, 2, '.', '' ) );
|
||||
|
||||
// Add product to cart x3, calc and test
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
WC()->cart->calculate_totals();
|
||||
$this->assertEquals( '29.00', number_format( WC()->cart->total, 2, '.', '' ) );
|
||||
$this->assertEquals( '1.00', number_format( WC()->cart->discount_cart, 2, '.', '' ) );
|
||||
|
@ -56,8 +56,8 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->remove_coupons();
|
||||
|
||||
# Test case 2 #10573
|
||||
update_post_meta( $product->id, '_regular_price', '29.95' );
|
||||
update_post_meta( $product->id, '_price', '29.95' );
|
||||
update_post_meta( $product->get_id(), '_regular_price', '29.95' );
|
||||
update_post_meta( $product->get_id(), '_price', '29.95' );
|
||||
update_post_meta( $coupon->get_id(), 'discount_type', 'percent' );
|
||||
update_post_meta( $coupon->get_id(), 'coupon_amount', '10' );
|
||||
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
||||
|
@ -74,9 +74,9 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
'tax_rate_class' => '',
|
||||
);
|
||||
WC_Tax::_insert_tax_rate( $tax_rate );
|
||||
$product = wc_get_product( $product->id );
|
||||
$product = wc_get_product( $product->get_id() );
|
||||
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
WC()->cart->add_discount( $coupon->get_code() );
|
||||
|
||||
WC()->cart->calculate_totals();
|
||||
|
@ -88,7 +88,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations" );
|
||||
WC()->cart->empty_cart();
|
||||
WC()->cart->remove_coupons();
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
|
||||
# Test case 3 #11626
|
||||
update_post_meta( $coupon->get_id(), 'discount_type', 'percent' );
|
||||
|
@ -122,10 +122,10 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
);
|
||||
foreach ( $products_data as $price ) {
|
||||
$loop_product = WC_Helper_Product::create_simple_product();
|
||||
$product_ids[] = $loop_product->id;
|
||||
update_post_meta( $loop_product->id, '_regular_price', $price );
|
||||
update_post_meta( $loop_product->id, '_price', $price );
|
||||
WC()->cart->add_to_cart( $loop_product->id, 1 );
|
||||
$product_ids[] = $loop_product->get_id();
|
||||
update_post_meta( $loop_product->get_id(), '_regular_price', $price );
|
||||
update_post_meta( $loop_product->get_id(), '_price', $price );
|
||||
WC()->cart->add_to_cart( $loop_product->get_id(), 1 );
|
||||
}
|
||||
|
||||
WC()->cart->add_discount( $coupon->get_code() );
|
||||
|
@ -179,7 +179,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Add the product to the cart. Methods returns boolean on failure, string on success.
|
||||
$this->assertNotFalse( WC()->cart->add_to_cart( $product->id, 1 ) );
|
||||
$this->assertNotFalse( WC()->cart->add_to_cart( $product->get_id(), 1 ) );
|
||||
|
||||
// Check if the item is in the cart
|
||||
$this->assertEquals( 1, WC()->cart->get_cart_contents_count() );
|
||||
|
@ -188,7 +188,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,19 +199,19 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
// Trash product
|
||||
wp_trash_post( $product->id );
|
||||
wp_trash_post( $product->get_id() );
|
||||
|
||||
// Refetch product, to be sure
|
||||
$product = wc_get_product( $product->id );
|
||||
$product = wc_get_product( $product->get_id() );
|
||||
|
||||
// Add product to cart
|
||||
$this->assertFalse( WC()->cart->add_to_cart( $product->id, 1 ) );
|
||||
$this->assertFalse( WC()->cart->add_to_cart( $product->get_id(), 1 ) );
|
||||
|
||||
// Clean up the cart
|
||||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,7 +225,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
$variation = array_shift( $variations );
|
||||
|
||||
// Add the product to the cart. Methods returns boolean on failure, string on success.
|
||||
$this->assertNotFalse( WC()->cart->add_to_cart( $product->id, 1, $variation['variation_id'], array( 'Size' => ucfirst( $variation['attributes']['attribute_pa_size'] ) ) ) );
|
||||
$this->assertNotFalse( WC()->cart->add_to_cart( $product->get_id(), 1, $variation['variation_id'], array( 'Size' => ucfirst( $variation['attributes']['attribute_pa_size'] ) ) ) );
|
||||
|
||||
// Check if the item is in the cart
|
||||
$this->assertEquals( 1, WC()->cart->get_cart_contents_count() );
|
||||
|
@ -247,10 +247,10 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
|
||||
// Set sold_individually to yes
|
||||
$product->sold_individually = 'yes';
|
||||
update_post_meta( $product->id, '_sold_individually', 'yes' );
|
||||
update_post_meta( $product->get_id(), '_sold_individually', 'yes' );
|
||||
|
||||
// Add the product twice to cart, should be corrected to 1. Methods returns boolean on failure, string on success.
|
||||
$this->assertNotFalse( WC()->cart->add_to_cart( $product->id, 2 ) );
|
||||
$this->assertNotFalse( WC()->cart->add_to_cart( $product->get_id(), 2 ) );
|
||||
|
||||
// Check if the item is in the cart
|
||||
$this->assertEquals( 1, WC()->cart->get_cart_contents_count() );
|
||||
|
@ -259,7 +259,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,10 +273,10 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Generate cart id
|
||||
$cart_id = WC()->cart->generate_cart_id( $product->id );
|
||||
$cart_id = WC()->cart->generate_cart_id( $product->get_id() );
|
||||
|
||||
// Get the product from the cart
|
||||
$this->assertNotEquals( '', WC()->cart->find_product_in_cart( $cart_id ) );
|
||||
|
@ -285,7 +285,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
|
||||
}
|
||||
|
||||
|
@ -355,10 +355,10 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
// Add 1 product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Get cart id
|
||||
$cart_id = WC()->cart->generate_cart_id( $product->id );
|
||||
$cart_id = WC()->cart->generate_cart_id( $product->get_id() );
|
||||
|
||||
// Set quantity of product in cart to 2
|
||||
$this->assertTrue( WC()->cart->set_quantity( $cart_id, 2 ) );
|
||||
|
@ -376,7 +376,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,7 +390,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Check cart validity, should pass
|
||||
$this->assertTrue( WC()->cart->check_cart_item_validity() );
|
||||
|
@ -399,7 +399,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Check
|
||||
$this->assertEquals( apply_filters( 'woocommerce_cart_total', wc_price( WC()->cart->total ) ), WC()->cart->get_total() );
|
||||
|
@ -428,7 +428,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -450,7 +450,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Calc total
|
||||
$total = WC()->cart->total - WC()->cart->tax_total - WC()->cart->shipping_tax_total;
|
||||
|
@ -465,7 +465,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
|
||||
// Restore option
|
||||
update_option( 'woocommerce_calc_taxes', 'no' );
|
||||
|
@ -492,8 +492,8 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
public function test_shipping_total() {
|
||||
// Create product
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
update_post_meta( $product->id, '_price', '10' );
|
||||
update_post_meta( $product->id, '_regular_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
||||
|
||||
// Create a flat rate method
|
||||
WC_Helper_Shipping::create_simple_flat_rate();
|
||||
|
@ -504,7 +504,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Set the flat_rate shipping method
|
||||
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
|
||||
|
@ -524,7 +524,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC_Helper_Shipping::delete_simple_flat_rate();
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -535,8 +535,8 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
public function test_cart_fee() {
|
||||
// Create product
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
update_post_meta( $product->id, '_price', '10' );
|
||||
update_post_meta( $product->id, '_regular_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
||||
|
||||
// We need this to have the calculate_totals() method calculate totals
|
||||
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
|
||||
|
@ -547,7 +547,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC_Helper_Fee::add_cart_fee();
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Test if the cart total amount is equal 20
|
||||
$this->assertEquals( 20, WC()->cart->total );
|
||||
|
@ -562,7 +562,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
WC_Helper_Fee::remove_cart_fee();
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,7 +92,7 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case {
|
|||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
// Add the product to the cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Empty the cart
|
||||
wc_empty_cart();
|
||||
|
@ -101,7 +101,7 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 0, WC()->cart->get_cart_contents_count() );
|
||||
|
||||
// Delete the previously created product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,11 +124,11 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case {
|
|||
public function test_wc_cart_totals_subtotal_html() {
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
$this->expectOutputString( wc_price( $product->price ), wc_cart_totals_subtotal_html() );
|
||||
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,22 +161,22 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case {
|
|||
public function test_wc_add_to_cart_message() {
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
$message = wc_add_to_cart_message( array( $product->id => 1 ), false, true );
|
||||
$message = wc_add_to_cart_message( array( $product->get_id() => 1 ), false, true );
|
||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View Cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||
|
||||
$message = wc_add_to_cart_message( array( $product->id => 3 ), false, true );
|
||||
$message = wc_add_to_cart_message( array( $product->get_id() => 3 ), false, true );
|
||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View Cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||
|
||||
$message = wc_add_to_cart_message( array( $product->id => 1 ), true, true );
|
||||
$message = wc_add_to_cart_message( array( $product->get_id() => 1 ), true, true );
|
||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View Cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||
|
||||
$message = wc_add_to_cart_message( array( $product->id => 3 ), true, true );
|
||||
$message = wc_add_to_cart_message( array( $product->get_id() => 3 ), true, true );
|
||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View Cart</a> 3 × “Dummy Product” have been added to your cart.', $message );
|
||||
|
||||
$message = wc_add_to_cart_message( $product->id, false, true );
|
||||
$message = wc_add_to_cart_message( $product->get_id(), false, true );
|
||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View Cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||
|
||||
$message = wc_add_to_cart_message( $product->id, true, true );
|
||||
$message = wc_add_to_cart_message( $product->get_id(), true, true );
|
||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View Cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,8 +73,8 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
|
||||
// Create product
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
update_post_meta( $product->id, '_price', '10' );
|
||||
update_post_meta( $product->id, '_regular_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
||||
|
||||
// Create coupon
|
||||
$coupon = WC_Helper_Coupon::create_coupon();
|
||||
|
@ -90,7 +90,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Add coupon
|
||||
WC()->cart->add_discount( $coupon->get_code() );
|
||||
|
@ -119,7 +119,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
WC_Helper_Coupon::delete_coupon( $coupon->get_id() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,8 +131,8 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
|
||||
// Create product
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
update_post_meta( $product->id, '_price', '10' );
|
||||
update_post_meta( $product->id, '_regular_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
||||
|
||||
// Create coupon
|
||||
$coupon = WC_Helper_Coupon::create_coupon();
|
||||
|
@ -148,7 +148,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Add coupon
|
||||
WC()->cart->add_discount( $coupon->get_code() );
|
||||
|
@ -177,7 +177,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
WC_Helper_Coupon::delete_coupon( $coupon->get_id() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,8 +189,8 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
|
||||
// Create product
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
update_post_meta( $product->id, '_price', '10' );
|
||||
update_post_meta( $product->id, '_regular_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
||||
|
||||
// Create coupon
|
||||
$coupon = WC_Helper_Coupon::create_coupon();
|
||||
|
@ -209,7 +209,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
WC_Helper_Fee::add_cart_fee();
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Add coupon
|
||||
WC()->cart->add_discount( $coupon->get_code() );
|
||||
|
@ -241,7 +241,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
WC_Helper_Coupon::delete_coupon( $coupon->get_id() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -253,8 +253,8 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
|
||||
// Create product
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
update_post_meta( $product->id, '_price', '10' );
|
||||
update_post_meta( $product->id, '_regular_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_price', '10' );
|
||||
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
||||
|
||||
// Create coupon
|
||||
$coupon = WC_Helper_Coupon::create_coupon();
|
||||
|
@ -273,7 +273,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
WC_Helper_Fee::add_cart_fee();
|
||||
|
||||
// Add product to cart
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Add coupon
|
||||
WC()->cart->add_discount( $coupon->get_code() );
|
||||
|
@ -305,6 +305,6 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
WC_Helper_Coupon::delete_coupon( $coupon->get_id() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class WC_Tests_Customer extends WC_Unit_Test_Case {
|
|||
|
||||
// Create dummy product, and add the product to the cart.
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Customer is going with the Local Pickup option, and the store calculates tax based on the store location.
|
||||
WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) );
|
||||
|
@ -53,7 +53,7 @@ class WC_Tests_Customer extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,7 +71,7 @@ class WC_Tests_Customer extends WC_Unit_Test_Case {
|
|||
// Create dummy product, and add the product to the cart.
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
WC()->cart->add_to_cart( $product->id, 1 );
|
||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||
|
||||
// Customer is going with the Local Pickup option, and the store calculates tax based on the store location.
|
||||
WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) );
|
||||
|
@ -102,6 +102,6 @@ class WC_Tests_Customer extends WC_Unit_Test_Case {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Clean up product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,42 +72,42 @@ class WC_Tests_Product_CRUD extends WC_Unit_Test_Case {
|
|||
*/
|
||||
public function test_product_getters_and_setters() {
|
||||
$getters_and_setters = array(
|
||||
'name' => 'Test',
|
||||
'slug' => 'test',
|
||||
'status' => 'publish',
|
||||
'catalog_visibility' => 'search',
|
||||
'featured' => false,
|
||||
'description' => 'Hello world',
|
||||
'short_description' => 'hello',
|
||||
'sku' => 'TEST SKU',
|
||||
'regular_price' => 15.00,
|
||||
'sale_price' => 10.00,
|
||||
'date_on_sale_from' => '1475798400',
|
||||
'date_on_sale_to' => '1477267200',
|
||||
'total_sales' => 20,
|
||||
'tax_status' => 'none',
|
||||
'tax_class' => '',
|
||||
'manage_stock' => true,
|
||||
'stock_quantity' => 10,
|
||||
'stock_status' => 'instock',
|
||||
'backorders' => 'notify',
|
||||
'sold_individually' => false,
|
||||
'weight' => 100,
|
||||
'length' => 10,
|
||||
'width' => 10,
|
||||
'height' => 10,
|
||||
'upsell_ids' => array( 2, 3 ),
|
||||
'cross_sell_ids' => array( 4, 5 ),
|
||||
'parent_id' => 0,
|
||||
'reviews_allowed' => true,
|
||||
'default_attributes' => array(),
|
||||
'purchase_note' => 'A note',
|
||||
'menu_order' => 2,
|
||||
'gallery_attachment_ids' => array(),
|
||||
'download_type' => 'standard',
|
||||
'download_expiry' => -1,
|
||||
'download_limit' => 5,
|
||||
'thumbnail_id' => 2,
|
||||
'name' => 'Test',
|
||||
'slug' => 'test',
|
||||
'status' => 'publish',
|
||||
'catalog_visibility' => 'search',
|
||||
'featured' => false,
|
||||
'description' => 'Hello world',
|
||||
'short_description' => 'hello',
|
||||
'sku' => 'TEST SKU',
|
||||
'regular_price' => 15.00,
|
||||
'sale_price' => 10.00,
|
||||
'date_on_sale_from' => '1475798400',
|
||||
'date_on_sale_to' => '1477267200',
|
||||
'total_sales' => 20,
|
||||
'tax_status' => 'none',
|
||||
'tax_class' => '',
|
||||
'manage_stock' => true,
|
||||
'stock_quantity' => 10,
|
||||
'stock_status' => 'instock',
|
||||
'backorders' => 'notify',
|
||||
'sold_individually' => false,
|
||||
'weight' => 100,
|
||||
'length' => 10,
|
||||
'width' => 10,
|
||||
'height' => 10,
|
||||
'upsell_ids' => array( 2, 3 ),
|
||||
'cross_sell_ids' => array( 4, 5 ),
|
||||
'parent_id' => 0,
|
||||
'reviews_allowed' => true,
|
||||
'default_attributes' => array(),
|
||||
'purchase_note' => 'A note',
|
||||
'menu_order' => 2,
|
||||
'gallery_image_ids' => array(),
|
||||
'download_type' => 'standard',
|
||||
'download_expiry' => -1,
|
||||
'download_limit' => 5,
|
||||
'image_id' => 2,
|
||||
);
|
||||
$product = new WC_Product;
|
||||
foreach ( $getters_and_setters as $function => $value ) {
|
||||
|
|
|
@ -134,8 +134,6 @@ class WC_Tests_Product_Functions extends WC_Unit_Test_Case {
|
|||
update_post_meta( $product->get_id(), '_manage_stock', 'yes' );
|
||||
|
||||
wc_update_product_stock( $product->get_id(), 5 );
|
||||
|
||||
$product = new WC_Product_Simple( $product->get_id() );
|
||||
$this->assertEquals( 5, $product->get_stock_quantity() );
|
||||
|
||||
// Delete Product
|
||||
|
|
|
@ -22,7 +22,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( __( 'Read more', 'woocommerce' ), $product->add_to_cart_text() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( __( 'Add to cart', 'woocommerce' ), $product->single_add_to_cart_text() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 'Dummy Product', $product->get_title() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,10 +64,10 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
// Create product
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
$this->assertEquals( get_permalink( $product->id ), $product->get_permalink() );
|
||||
$this->assertEquals( get_permalink( $product->get_id() ), $product->get_permalink() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +82,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( $product->sku, $product->get_sku() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,25 +101,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_total_stock().
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public function test_get_total_stock() {
|
||||
// Create product
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
|
||||
$this->assertEmpty( $product->get_total_stock() );
|
||||
|
||||
$product->manage_stock = 'yes';
|
||||
$this->assertEquals( 0, $product->get_total_stock() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,7 +119,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 5, $product->set_stock( 3, 'add' ) );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,7 +136,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 2, $product->reduce_stock( 3 ) );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,7 +153,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 8, $product->increase_stock( 3 ) );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,7 +171,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertFalse( $product->is_type( 'external' ) );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,7 +192,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertFalse( $product->is_downloadable() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,7 +213,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertFalse( $product->is_virtual() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,7 +232,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertTrue( $product->needs_shipping() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -269,7 +251,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertFalse( $product->is_sold_individually() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -291,7 +273,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertFalse( $product->backorders_allowed() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -318,6 +300,6 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
|
|||
$this->assertFalse( $product->backorders_require_notification() );
|
||||
|
||||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->id );
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue