diff --git a/includes/abstracts/abstract-wc-data.php b/includes/abstracts/abstract-wc-data.php
index 443de6f1e00..588e6505ef2 100644
--- a/includes/abstracts/abstract-wc-data.php
+++ b/includes/abstracts/abstract-wc-data.php
@@ -200,16 +200,32 @@ abstract class WC_Data {
* @return int
*/
public function save() {
- if ( $this->data_store ) {
- // Trigger action before saving to the DB. Allows you to adjust object props before save.
- do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
-
- if ( $this->get_id() ) {
- $this->data_store->update( $this );
- } else {
- $this->data_store->create( $this );
- }
+ if ( ! $this->data_store ) {
+ return $this->get_id();
}
+
+ /**
+ * Trigger action before saving to the DB. Allows you to adjust object props before save.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
+
+ if ( $this->get_id() ) {
+ $this->data_store->update( $this );
+ } else {
+ $this->data_store->create( $this );
+ }
+
+ /**
+ * Trigger action after saving to the DB.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_after_' . $this->object_type . '_object_save', $this, $this->data_store );
+
return $this->get_id();
}
diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php
index 78d470ff72e..627ca69db23 100644
--- a/includes/abstracts/abstract-wc-order.php
+++ b/includes/abstracts/abstract-wc-order.php
@@ -165,8 +165,17 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* @return int order ID
*/
public function save() {
- if ( $this->data_store ) {
- // Trigger action before saving to the DB. Allows you to adjust object props before save.
+ if ( ! $this->data_store ) {
+ return $this->get_id();
+ }
+
+ try {
+ /**
+ * Trigger action before saving to the DB. Allows you to adjust object props before save.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
if ( $this->get_id() ) {
@@ -174,8 +183,30 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
} else {
$this->data_store->create( $this );
}
+
+ $this->save_items();
+
+ /**
+ * Trigger action after saving to the DB.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_after_' . $this->object_type . '_object_save', $this, $this->data_store );
+
+ } catch ( Exception $e ) {
+ wc_get_logger()->error(
+ sprintf(
+ 'Error saving order #%d',
+ $this->get_id()
+ ),
+ array(
+ 'order' => $this,
+ 'error' => $e,
+ )
+ );
}
- $this->save_items();
+
return $this->get_id();
}
diff --git a/includes/abstracts/abstract-wc-product.php b/includes/abstracts/abstract-wc-product.php
index 85357d13d8c..9403817a637 100644
--- a/includes/abstracts/abstract-wc-product.php
+++ b/includes/abstracts/abstract-wc-product.php
@@ -1360,19 +1360,36 @@ class WC_Product extends WC_Abstract_Legacy_Product {
public function save() {
$this->validate_props();
- if ( $this->data_store ) {
- // Trigger action before saving to the DB. Use a pointer to adjust object props before save.
- do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
-
- if ( $this->get_id() ) {
- $this->data_store->update( $this );
- } else {
- $this->data_store->create( $this );
- }
- if ( $this->get_parent_id() ) {
- wc_deferred_product_sync( $this->get_parent_id() );
- }
+ if ( ! $this->data_store ) {
+ return $this->get_id();
}
+
+ /**
+ * Trigger action before saving to the DB. Allows you to adjust object props before save.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
+
+ if ( $this->get_id() ) {
+ $this->data_store->update( $this );
+ } else {
+ $this->data_store->create( $this );
+ }
+
+ if ( $this->get_parent_id() ) {
+ wc_deferred_product_sync( $this->get_parent_id() );
+ }
+
+ /**
+ * Trigger action after saving to the DB.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_after_' . $this->object_type . '_object_save', $this, $this->data_store );
+
return $this->get_id();
}
diff --git a/includes/class-wc-customer-download.php b/includes/class-wc-customer-download.php
index 6db6d02e6ec..26dadb0f46d 100644
--- a/includes/class-wc-customer-download.php
+++ b/includes/class-wc-customer-download.php
@@ -332,32 +332,6 @@ WHERE permission_id = %d",
$download_log->save();
}
- /*
- |--------------------------------------------------------------------------
- | CRUD methods
- |--------------------------------------------------------------------------
- */
-
- /**
- * Save data to the database.
- *
- * @since 3.0.0
- * @return int Item ID
- */
- public function save() {
- if ( $this->data_store ) {
- // Trigger action before saving to the DB. Use a pointer to adjust object props before save.
- do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
-
- if ( $this->get_id() ) {
- $this->data_store->update( $this );
- } else {
- $this->data_store->create( $this );
- }
- }
- return $this->get_id();
- }
-
/*
|--------------------------------------------------------------------------
| ArrayAccess/Backwards compatibility.
diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php
index 429720d3fbf..b030419eb48 100644
--- a/includes/class-wc-order.php
+++ b/includes/class-wc-order.php
@@ -128,7 +128,11 @@ class WC_Order extends WC_Abstract_Order {
*/
$logger = wc_get_logger();
$logger->error(
- sprintf( 'Error completing payment for order #%d', $this->get_id() ), array(
+ sprintf(
+ 'Error completing payment for order #%d',
+ $this->get_id()
+ ),
+ array(
'order' => $this,
'error' => $e,
)
@@ -175,7 +179,7 @@ class WC_Order extends WC_Abstract_Order {
}
if ( $total_refunded && $display_refunded ) {
- $formatted_total = '' . strip_tags( $formatted_total ) . ' ' . wc_price( $order_total - $total_refunded, array( 'currency' => $this->get_currency() ) ) . $tax_string . '';
+ $formatted_total = '' . wp_strip_all_tags( $formatted_total ) . ' ' . wc_price( $order_total - $total_refunded, array( 'currency' => $this->get_currency() ) ) . $tax_string . '';
} else {
$formatted_total .= $tax_string;
}
@@ -212,32 +216,9 @@ class WC_Order extends WC_Abstract_Order {
* @return int order ID
*/
public function save() {
- try {
- $this->maybe_set_user_billing_email();
-
- if ( $this->data_store ) {
- // Trigger action before saving to the DB. Allows you to adjust object props before save.
- do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
-
- if ( $this->get_id() ) {
- $this->data_store->update( $this );
- } else {
- $this->data_store->create( $this );
- }
- }
-
- $this->save_items();
- $this->status_transition();
- } catch ( Exception $e ) {
- $logger = wc_get_logger();
- $logger->error(
- sprintf( 'Error saving order #%d', $this->get_id() ), array(
- 'order' => $this,
- 'error' => $e,
- )
- );
- $this->add_order_note( __( 'Error saving order.', 'woocommerce' ) . ' ' . $e->getMessage() );
- }
+ $this->maybe_set_user_billing_email();
+ parent::save();
+ $this->status_transition();
return $this->get_id();
}
@@ -335,7 +316,11 @@ class WC_Order extends WC_Abstract_Order {
} catch ( Exception $e ) {
$logger = wc_get_logger();
$logger->error(
- sprintf( 'Error updating status for order #%d', $this->get_id() ), array(
+ sprintf(
+ 'Error updating status for order #%d',
+ $this->get_id()
+ ),
+ array(
'order' => $this,
'error' => $e,
)
@@ -375,7 +360,11 @@ class WC_Order extends WC_Abstract_Order {
} catch ( Exception $e ) {
$logger = wc_get_logger();
$logger->error(
- sprintf( 'Status transition of order #%d errored!', $this->get_id() ), array(
+ sprintf(
+ 'Status transition of order #%d errored!',
+ $this->get_id()
+ ),
+ array(
'order' => $this,
'error' => $e,
)
@@ -1513,7 +1502,8 @@ class WC_Order extends WC_Abstract_Order {
array(
'pay_for_order' => 'true',
'key' => $this->get_order_key(),
- ), $pay_url
+ ),
+ $pay_url
);
}
@@ -1545,15 +1535,18 @@ class WC_Order extends WC_Abstract_Order {
*/
public function get_cancel_order_url( $redirect = '' ) {
return apply_filters(
- 'woocommerce_get_cancel_order_url', wp_nonce_url(
+ 'woocommerce_get_cancel_order_url',
+ wp_nonce_url(
add_query_arg(
array(
'cancel_order' => 'true',
'order' => $this->get_order_key(),
'order_id' => $this->get_id(),
'redirect' => $redirect,
- ), $this->get_cancel_endpoint()
- ), 'woocommerce-cancel_order'
+ ),
+ $this->get_cancel_endpoint()
+ ),
+ 'woocommerce-cancel_order'
)
);
}
@@ -1566,14 +1559,16 @@ class WC_Order extends WC_Abstract_Order {
*/
public function get_cancel_order_url_raw( $redirect = '' ) {
return apply_filters(
- 'woocommerce_get_cancel_order_url_raw', add_query_arg(
+ 'woocommerce_get_cancel_order_url_raw',
+ add_query_arg(
array(
'cancel_order' => 'true',
'order' => $this->get_order_key(),
'order_id' => $this->get_id(),
'redirect' => $redirect,
'_wpnonce' => wp_create_nonce( 'woocommerce-cancel_order' ),
- ), $this->get_cancel_endpoint()
+ ),
+ $this->get_cancel_endpoint()
)
);
}
@@ -1669,7 +1664,8 @@ class WC_Order extends WC_Abstract_Order {
add_comment_meta( $comment_id, 'is_customer_note', 1 );
do_action(
- 'woocommerce_new_customer_note', array(
+ 'woocommerce_new_customer_note',
+ array(
'order_id' => $this->get_id(),
'customer_note' => $commentdata['comment_content'],
)
diff --git a/includes/class-wc-product-variable.php b/includes/class-wc-product-variable.php
index 12de1b68ed7..04a6197c4c8 100644
--- a/includes/class-wc-product-variable.php
+++ b/includes/class-wc-product-variable.php
@@ -325,7 +325,8 @@ class WC_Product_Variable extends WC_Product {
$show_variation_price = apply_filters( 'woocommerce_show_variation_price', $variation->get_price() === '' || $this->get_variation_sale_price( 'min' ) !== $this->get_variation_sale_price( 'max' ) || $this->get_variation_regular_price( 'min' ) !== $this->get_variation_regular_price( 'max' ), $this, $variation );
return apply_filters(
- 'woocommerce_available_variation', array(
+ 'woocommerce_available_variation',
+ array(
'attributes' => $variation->get_variation_attributes(),
'availability_html' => wc_get_stock_html( $variation ),
'backorders_allowed' => $variation->backorders_allowed(),
@@ -350,7 +351,9 @@ class WC_Product_Variable extends WC_Product {
'variation_is_visible' => $variation->variation_is_visible(),
'weight' => $variation->get_weight(),
'weight_html' => wc_format_weight( $variation->get_weight() ),
- ), $this, $variation
+ ),
+ $this,
+ $variation
);
}
@@ -434,25 +437,41 @@ class WC_Product_Variable extends WC_Product {
*/
public function save() {
$this->validate_props();
- if ( $this->data_store ) {
- // Trigger action before saving to the DB. Allows you to adjust object props before save.
- do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
-
- // Get names before save.
- $previous_name = $this->data['name'];
- $new_name = $this->get_name( 'edit' );
-
- if ( $this->get_id() ) {
- $this->data_store->update( $this );
- } else {
- $this->data_store->create( $this );
- }
-
- $this->data_store->sync_variation_names( $this, $previous_name, $new_name );
- $this->data_store->sync_managed_variation_stock_status( $this );
+ if ( ! $this->data_store ) {
return $this->get_id();
}
+
+ /**
+ * Trigger action before saving to the DB. Allows you to adjust object props before save.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
+
+ // Get names before save.
+ $previous_name = $this->data['name'];
+ $new_name = $this->get_name( 'edit' );
+
+ if ( $this->get_id() ) {
+ $this->data_store->update( $this );
+ } else {
+ $this->data_store->create( $this );
+ }
+
+ $this->data_store->sync_variation_names( $this, $previous_name, $new_name );
+ $this->data_store->sync_managed_variation_stock_status( $this );
+
+ /**
+ * Trigger action after saving to the DB.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_after_' . $this->object_type . '_object_save', $this, $this->data_store );
+
+ return $this->get_id();
}
/*
@@ -587,10 +606,13 @@ class WC_Product_Variable extends WC_Product {
}
wc_do_deprecated_action(
- 'woocommerce_variable_product_sync', array(
+ 'woocommerce_variable_product_sync',
+ array(
$product->get_id(),
$product->get_visible_children(),
- ), '3.0', 'woocommerce_variable_product_sync_data, woocommerce_new_product or woocommerce_update_product'
+ ),
+ '3.0',
+ 'woocommerce_variable_product_sync_data, woocommerce_new_product or woocommerce_update_product'
);
}
diff --git a/includes/class-wc-shipping-zone.php b/includes/class-wc-shipping-zone.php
index a2f201bc197..aa1a5c07e0b 100644
--- a/includes/class-wc-shipping-zone.php
+++ b/includes/class-wc-shipping-zone.php
@@ -259,17 +259,34 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
if ( ! $this->get_zone_name() ) {
$this->set_zone_name( $this->generate_zone_name() );
}
- if ( $this->data_store ) {
- // Trigger action before saving to the DB. Allows you to adjust object props before save.
- do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
- if ( null === $this->get_id() ) {
- $this->data_store->create( $this );
- } else {
- $this->data_store->update( $this );
- }
+ if ( ! $this->data_store ) {
return $this->get_id();
}
+
+ /**
+ * Trigger action before saving to the DB. Allows you to adjust object props before save.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store );
+
+ if ( null === $this->get_id() ) {
+ $this->data_store->update( $this );
+ } else {
+ $this->data_store->create( $this );
+ }
+
+ /**
+ * Trigger action after saving to the DB.
+ *
+ * @param WC_Data $this The object being saved.
+ * @param WC_Data_Store_WP $data_store THe data store persisting the data.
+ */
+ do_action( 'woocommerce_after_' . $this->object_type . '_object_save', $this, $this->data_store );
+
+ return $this->get_id();
}
/**