Skip to content

Instantly share code, notes, and snippets.

@kreamweb
Created November 7, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreamweb/dbec685a6309ab2a3547c7195e250d20 to your computer and use it in GitHub Desktop.
Save kreamweb/dbec685a6309ab2a3547c7195e250d20 to your computer and use it in GitHub Desktop.
add custom fields from the parent order to the renew order
<?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