kreamweb
11/7/2018 - 4:47 PM

[YITH WooCommerce Subscription] Integration with WooCommerce Extra Checkout Fields for Brazil

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();
	}
}