2016-11-17 16:53:13 +00:00
|
|
|
<?php
|
2018-03-08 18:32:23 +00:00
|
|
|
/**
|
|
|
|
* Class WC_Order_Refund_Data_Store_CPT file.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\DataStores
|
|
|
|
*/
|
|
|
|
|
2016-11-17 16:53:13 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WC Order Refund Data Store: Stored in CPT.
|
|
|
|
*
|
2017-03-15 16:36:53 +00:00
|
|
|
* @version 3.0.0
|
2016-11-17 16:53:13 +00:00
|
|
|
*/
|
2016-11-22 13:54:51 +00:00
|
|
|
class WC_Order_Refund_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implements WC_Object_Data_Store_Interface, WC_Order_Refund_Data_Store_Interface {
|
2016-11-17 16:53:13 +00:00
|
|
|
|
2016-11-21 23:48:49 +00:00
|
|
|
/**
|
|
|
|
* Data stored in meta keys, but not considered "meta" for an order.
|
2018-03-07 19:16:01 +00:00
|
|
|
*
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2016-11-21 23:48:49 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $internal_meta_keys = array(
|
|
|
|
'_order_currency',
|
|
|
|
'_cart_discount',
|
|
|
|
'_refund_amount',
|
|
|
|
'_refunded_by',
|
2017-12-15 16:23:26 +00:00
|
|
|
'_refunded_payment',
|
2016-11-21 23:48:49 +00:00
|
|
|
'_refund_reason',
|
|
|
|
'_cart_discount_tax',
|
|
|
|
'_order_shipping',
|
|
|
|
'_order_shipping_tax',
|
|
|
|
'_order_tax',
|
|
|
|
'_order_total',
|
|
|
|
'_order_version',
|
|
|
|
'_prices_include_tax',
|
|
|
|
'_payment_tokens',
|
|
|
|
);
|
|
|
|
|
2017-02-15 17:02:01 +00:00
|
|
|
/**
|
|
|
|
* Delete a refund - no trash is supported.
|
2018-03-07 19:16:01 +00:00
|
|
|
*
|
2018-03-08 18:32:23 +00:00
|
|
|
* @param WC_Order $order Order object.
|
2018-03-07 19:16:01 +00:00
|
|
|
* @param array $args Array of args to pass to the delete method.
|
2017-02-15 17:02:01 +00:00
|
|
|
*/
|
|
|
|
public function delete( &$order, $args = array() ) {
|
|
|
|
$id = $order->get_id();
|
|
|
|
|
2017-05-30 13:44:28 +00:00
|
|
|
if ( ! $id ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-15 17:02:01 +00:00
|
|
|
wp_delete_post( $id );
|
|
|
|
$order->set_id( 0 );
|
2017-02-16 12:33:47 +00:00
|
|
|
do_action( 'woocommerce_delete_order_refund', $id );
|
2017-02-15 17:02:01 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 16:53:13 +00:00
|
|
|
/**
|
|
|
|
* Read refund data. Can be overridden by child classes to load other props.
|
|
|
|
*
|
2019-04-21 19:55:13 +00:00
|
|
|
* @param WC_Order_Refund $refund Refund object.
|
|
|
|
* @param object $post_object Post object.
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2016-11-17 16:53:13 +00:00
|
|
|
*/
|
|
|
|
protected function read_order_data( &$refund, $post_object ) {
|
|
|
|
parent::read_order_data( $refund, $post_object );
|
|
|
|
$id = $refund->get_id();
|
2018-03-07 19:16:01 +00:00
|
|
|
$refund->set_props(
|
|
|
|
array(
|
2018-03-19 18:05:36 +00:00
|
|
|
'amount' => get_post_meta( $id, '_refund_amount', true ),
|
2019-04-22 21:05:34 +00:00
|
|
|
'refunded_by' => metadata_exists( 'post', $id, '_refunded_by' ) ? get_post_meta( $id, '_refunded_by', true ) : absint( $post_object->post_author ),
|
2018-03-19 18:05:36 +00:00
|
|
|
'refunded_payment' => wc_string_to_bool( get_post_meta( $id, '_refunded_payment', true ) ),
|
2019-04-22 21:05:34 +00:00
|
|
|
'reason' => metadata_exists( 'post', $id, '_refund_reason' ) ? get_post_meta( $id, '_refund_reason', true ) : $post_object->post_excerpt,
|
2018-03-07 19:16:01 +00:00
|
|
|
)
|
|
|
|
);
|
2016-11-17 16:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.
|
|
|
|
*
|
2019-04-21 19:55:13 +00:00
|
|
|
* @param WC_Order_Refund $refund Refund object.
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2016-11-17 16:53:13 +00:00
|
|
|
*/
|
2017-01-23 20:20:29 +00:00
|
|
|
protected function update_post_meta( &$refund ) {
|
|
|
|
parent::update_post_meta( $refund );
|
2016-11-23 13:18:49 +00:00
|
|
|
|
2016-11-17 16:53:13 +00:00
|
|
|
$updated_props = array();
|
|
|
|
$meta_key_to_props = array(
|
2017-12-15 16:23:26 +00:00
|
|
|
'_refund_amount' => 'amount',
|
|
|
|
'_refunded_by' => 'refunded_by',
|
|
|
|
'_refunded_payment' => 'refunded_payment',
|
|
|
|
'_refund_reason' => 'reason',
|
2016-11-17 16:53:13 +00:00
|
|
|
);
|
|
|
|
|
2017-01-23 20:20:29 +00:00
|
|
|
$props_to_update = $this->get_props_to_update( $refund, $meta_key_to_props );
|
|
|
|
foreach ( $props_to_update as $meta_key => $prop ) {
|
2016-11-17 16:53:13 +00:00
|
|
|
$value = $refund->{"get_$prop"}( 'edit' );
|
2017-01-23 20:20:29 +00:00
|
|
|
update_post_meta( $refund->get_id(), $meta_key, $value );
|
|
|
|
$updated_props[] = $prop;
|
2016-11-17 16:53:13 +00:00
|
|
|
}
|
2017-01-24 21:38:02 +00:00
|
|
|
|
|
|
|
do_action( 'woocommerce_order_refund_object_updated_props', $refund, $updated_props );
|
2016-11-17 16:53:13 +00:00
|
|
|
}
|
2016-11-21 16:46:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a title for the new post type.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function get_post_title() {
|
2018-03-08 18:32:23 +00:00
|
|
|
return sprintf(
|
|
|
|
/* translators: %s: Order date */
|
|
|
|
__( 'Refund – %s', 'woocommerce' ),
|
|
|
|
strftime( _x( '%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce' ) ) // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.UnorderedPlaceholdersText
|
|
|
|
);
|
2016-11-21 16:46:32 +00:00
|
|
|
}
|
2016-11-17 16:53:13 +00:00
|
|
|
}
|