rebase on oct-10-2023
This commit is contained in:
@@ -195,6 +195,19 @@ abstract class WC_Data {
|
||||
* @return bool result
|
||||
*/
|
||||
public function delete( $force_delete = false ) {
|
||||
/**
|
||||
* Filters whether an object deletion should take place. Equivalent to `pre_delete_post`.
|
||||
*
|
||||
* @param mixed $check Whether to go ahead with deletion.
|
||||
* @param WC_Data $this The data object being deleted.
|
||||
* @param bool $force_delete Whether to bypass the trash.
|
||||
*
|
||||
* @since 8.1.0.
|
||||
*/
|
||||
$check = apply_filters( "woocommerce_pre_delete_$this->object_type", null, $this, $force_delete );
|
||||
if ( null !== $check ) {
|
||||
return $check;
|
||||
}
|
||||
if ( $this->data_store ) {
|
||||
$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
|
||||
$this->set_id( 0 );
|
||||
@@ -761,7 +774,7 @@ abstract class WC_Data {
|
||||
if ( ! $errors ) {
|
||||
$errors = new WP_Error();
|
||||
}
|
||||
$errors->add( $e->getErrorCode(), $e->getMessage() );
|
||||
$errors->add( $e->getErrorCode(), $e->getMessage(), array( 'property_name' => $prop ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||
/**
|
||||
* This method overwrites the base class's clone method to make it a no-op. In base class WC_Data, we are unsetting the meta_id to clone.
|
||||
* It seems like this was done to avoid conflicting the metadata when duplicating products. However, doing that does not seems necessary for orders.
|
||||
* In-fact, when we do that for orders, we lose the capability to clone orders with custom meta data by caching plugins. This is because, when we clone an order object for caching, it will clone the metadata without the ID. Unfortunately, when this cached object with nulled meta ID is retreived, WC_Data will consider it as a new meta and will insert it as a new meta-data causing duplicates.
|
||||
* In-fact, when we do that for orders, we lose the capability to clone orders with custom meta data by caching plugins. This is because, when we clone an order object for caching, it will clone the metadata without the ID. Unfortunately, when this cached object with nulled meta ID is retrieved, WC_Data will consider it as a new meta and will insert it as a new meta-data causing duplicates.
|
||||
*
|
||||
* Eventually, we should move away from overwriting the __clone method in base class itself, since it's easily possible to still duplicate the product without having to hook into the __clone method.
|
||||
*
|
||||
@@ -489,9 +489,9 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||
*/
|
||||
public function get_total_discount( $ex_tax = true ) {
|
||||
if ( $ex_tax ) {
|
||||
$total_discount = $this->get_discount_total();
|
||||
$total_discount = (float) $this->get_discount_total();
|
||||
} else {
|
||||
$total_discount = $this->get_discount_total() + $this->get_discount_tax();
|
||||
$total_discount = (float) $this->get_discount_total() + (float) $this->get_discount_tax();
|
||||
}
|
||||
return apply_filters( 'woocommerce_order_get_total_discount', NumberUtil::round( $total_discount, WC_ROUNDING_PRECISION ), $this );
|
||||
}
|
||||
@@ -638,7 +638,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||
}
|
||||
|
||||
// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
|
||||
if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses(), true ) && ! in_array( $old_status, $status_exceptions, true ) ) {
|
||||
if ( $old_status && ( 'auto-draft' === $old_status || ( ! in_array( 'wc-' . $old_status, $this->get_valid_statuses(), true ) && ! in_array( $old_status, $status_exceptions, true ) ) ) ) {
|
||||
$old_status = 'pending';
|
||||
}
|
||||
}
|
||||
@@ -810,6 +810,16 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||
* @param string $type Order item type. Default null.
|
||||
*/
|
||||
public function remove_order_items( $type = null ) {
|
||||
|
||||
/**
|
||||
* Trigger action before removing all order line items. Allows you to track order items.
|
||||
*
|
||||
* @param WC_Order $this The current order object.
|
||||
* @param string $type Order item type. Default null.
|
||||
*
|
||||
* @since 7.8.0
|
||||
*/
|
||||
do_action( 'woocommerce_remove_order_items', $this, $type );
|
||||
if ( ! empty( $type ) ) {
|
||||
$this->data_store->delete_items( $this, $type );
|
||||
|
||||
@@ -822,6 +832,15 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||
$this->data_store->delete_items( $this );
|
||||
$this->items = array();
|
||||
}
|
||||
/**
|
||||
* Trigger action after removing all order line items.
|
||||
*
|
||||
* @param WC_Order $this The current order object.
|
||||
* @param string $type Order item type. Default null.
|
||||
*
|
||||
* @since 7.8.0
|
||||
*/
|
||||
do_action( 'woocommerce_removed_order_items', $this, $type );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1944,7 +1963,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||
$subtotal = floatval( $item->get_subtotal() ) / $item->get_quantity();
|
||||
}
|
||||
|
||||
$subtotal = $round ? number_format( (float) $subtotal, wc_get_price_decimals(), '.', '' ) : $subtotal;
|
||||
$subtotal = $round ? NumberUtil::round( $subtotal, wc_get_price_decimals() ) : $subtotal;
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_order_amount_item_subtotal', $subtotal, $this, $item, $inc_tax, $round );
|
||||
@@ -2157,7 +2176,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||
} else {
|
||||
|
||||
// Show shipping including tax.
|
||||
$shipping = wc_price( $this->get_shipping_total() + $this->get_shipping_tax(), array( 'currency' => $this->get_currency() ) );
|
||||
$shipping = wc_price( (float) $this->get_shipping_total() + (float) $this->get_shipping_tax(), array( 'currency' => $this->get_currency() ) );
|
||||
|
||||
if ( (float) $this->get_shipping_tax() > 0 && ! $this->get_prices_include_tax() ) {
|
||||
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>', $this, $tax_display );
|
||||
|
||||
@@ -781,7 +781,9 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
||||
* @param string $visibility Options: 'hidden', 'visible', 'search' and 'catalog'.
|
||||
*/
|
||||
public function set_catalog_visibility( $visibility ) {
|
||||
$options = array_keys( wc_get_product_visibility_options() );
|
||||
$options = array_keys( wc_get_product_visibility_options() );
|
||||
$visibility = in_array( $visibility, $options, true ) ? $visibility : strtolower( $visibility );
|
||||
|
||||
if ( ! in_array( $visibility, $options, true ) ) {
|
||||
$this->error( 'product_invalid_catalog_visibility', __( 'Invalid catalog visibility option.', 'woocommerce' ) );
|
||||
}
|
||||
@@ -911,6 +913,8 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
||||
$status = 'taxable';
|
||||
}
|
||||
|
||||
$status = strtolower( $status );
|
||||
|
||||
if ( ! in_array( $status, $options, true ) ) {
|
||||
$this->error( 'product_invalid_tax_status', __( 'Invalid product tax status.', 'woocommerce' ) );
|
||||
}
|
||||
@@ -1110,7 +1114,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
||||
* position - integer sort order.
|
||||
* visible - If visible on frontend.
|
||||
* variation - If used for variations.
|
||||
* Indexed by unqiue key to allow clearing old ones after a set.
|
||||
* Indexed by unique key to allow clearing old ones after a set.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param array $raw_attributes Array of WC_Product_Attribute objects.
|
||||
@@ -1386,7 +1390,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
||||
return;
|
||||
}
|
||||
|
||||
$stock_is_above_notification_threshold = ( $this->get_stock_quantity() > get_option( 'woocommerce_notify_no_stock_amount', 0 ) );
|
||||
$stock_is_above_notification_threshold = ( (int) $this->get_stock_quantity() > absint( get_option( 'woocommerce_notify_no_stock_amount', 0 ) ) );
|
||||
$backorders_are_allowed = ( 'no' !== $this->get_backorders() );
|
||||
|
||||
if ( $stock_is_above_notification_threshold ) {
|
||||
@@ -1932,6 +1936,23 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
||||
return apply_filters( 'woocommerce_product_single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the aria-describedby description for the add to cart button.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function add_to_cart_aria_describedby() {
|
||||
/**
|
||||
* Filter the aria-describedby description for the add to cart button.
|
||||
*
|
||||
* @since 7.8.0
|
||||
*
|
||||
* @param string $var Text for the 'aria-describedby' attribute.
|
||||
* @param WC_Product $this Product object.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_product_add_to_cart_aria_describedby', '', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the add to cart button text.
|
||||
*
|
||||
|
||||
@@ -212,6 +212,21 @@ abstract class WC_Settings_API {
|
||||
if ( 'title' !== $this->get_field_type( $field ) ) {
|
||||
try {
|
||||
$this->settings[ $key ] = $this->get_field_value( $key, $field, $post_data );
|
||||
if ( 'select' === $field['type'] || 'checkbox' === $field['type'] ) {
|
||||
/**
|
||||
* Notify that a non-option setting has been updated.
|
||||
*
|
||||
* @since 7.8.0
|
||||
*/
|
||||
do_action(
|
||||
'woocommerce_update_non_option_setting',
|
||||
array(
|
||||
'id' => $key,
|
||||
'type' => $field['type'],
|
||||
'value' => $this->settings[ $key ],
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
$this->add_error( $e->getMessage() );
|
||||
}
|
||||
@@ -219,8 +234,8 @@ abstract class WC_Settings_API {
|
||||
}
|
||||
|
||||
$option_key = $this->get_option_key();
|
||||
do_action( 'woocommerce_update_option', array( 'id' => $option_key ) );
|
||||
return update_option( $option_key, apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );
|
||||
do_action( 'woocommerce_update_option', array( 'id' => $option_key ) ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
|
||||
return update_option( $option_key, apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -729,7 +744,7 @@ abstract class WC_Settings_API {
|
||||
'options' => array(),
|
||||
);
|
||||
|
||||
$data = wp_parse_args( $data, $defaults );
|
||||
$data = wp_parse_args( $data, $defaults );
|
||||
$value = $this->get_option( $key );
|
||||
|
||||
ob_start();
|
||||
|
||||
@@ -134,6 +134,30 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
|
||||
*/
|
||||
public $countries = array();
|
||||
|
||||
/**
|
||||
* Shipping method order.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $method_order;
|
||||
|
||||
/**
|
||||
* Whether the shipping method has settings or not. Preferably, use {@see has_settings()} instead.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $has_settings;
|
||||
|
||||
/**
|
||||
* When the method supports the settings modal, this is the admin settings HTML.
|
||||
* Preferably, use {@see get_admin_options_html()} instead.
|
||||
*
|
||||
* @var string|bool
|
||||
*/
|
||||
public $settings_html;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user