Created
November 7, 2018 16:47
-
-
Save kreamweb/dbec685a6309ab2a3547c7195e250d20 to your computer and use it in GitHub Desktop.
add custom fields from the parent order to the renew order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( class_exists( 'YITH_WC_Subscription' ) ) { | |
add_action( 'ywsbs_renew_subscription', 'ywsbs_renew_subscription_add_custom_field', 10, 2 ); | |
function ywsbs_renew_subscription_add_custom_field( $order_id, $subscription_id ) { | |
$subscription = ywsbs_get_subscription( $subscription_id ); | |
$parent_order = $subscription->get_order(); | |
$renew_order = wc_get_order( $order_id ); | |
$meta_list = array( | |
'_billing_birthdate', | |
'_billing_cpf', | |
'_billing_cnpj', | |
'_billing_sex', | |
'_billing_number', | |
'_billing_neighborhood', | |
'_billing_cellphone', | |
'_shipping_neighborhood', | |
'_shipping_number' | |
); | |
foreach ( $meta_list as $meta ) { | |
$renew_order->update_meta_data( $meta, $parent_order->get_meta( $meta ) ); | |
} | |
$renew_order->save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment