1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
<?php
defined( 'ABSPATH' ) || exit();
class WC_Braintree_Subscription_Data_Store_CPT extends WC_Order_Data_Store_CPT {
const data_type = 'braintree_subscription';
private $subscription_internal_meta_keys = array(
'_merchant_account_id',
'_trial_end_date',
'_subscription_trial_length',
'_subscription_trial_period',
'_start_date',
'_first_payment_date',
'_next_payment_date',
'_end_date',
'_previous_payment_date',
'_braintree_plan',
'_subscription_period',
'_subscription_period_interval',
'_subscription_length',
'_created_in_braintree',
'_recurring_cart_key',
);
public static function init() {
add_filter( 'woocommerce_data_stores', array( __CLASS__, 'add_data_store' ) );
}
public static function add_data_store( $data_stores ) {
$data_stores[ self::data_type ] = __CLASS__;
return $data_stores;
}
public function update_post_meta( &$order ) {
$id = $order->get_id();
parent::update_post_meta( $order );
foreach ( $this->get_props_to_update( $order, $this->meta_keys_to_props() ) as $meta_key => $prop ) {
$value = $order->{"get_$prop"}( 'edit' );
update_post_meta( $id, $meta_key, $value );
}
}
private function meta_keys_to_props() {
$keys = array();
foreach ( $this->subscription_internal_meta_keys as $key ) {
$keys[ $key ] = substr( $key, 1 );
}
return $keys;
}
}
WC_Braintree_Subscription_Data_Store_CPT::init();