load_custom_fields(); add_action('woocommerce_checkout_update_order_meta', array($this, 'save_custom_fields')); } private function load_custom_fields() { $settings = get_option('enspireplugins_acfw_settings', array()); $this->custom_fields = isset($settings['custom_fields']) ? $settings['custom_fields'] : array(); } public function get_custom_fields() { return $this->custom_fields; } public function save_custom_fields($order_id) { if (!isset($_POST['woocommerce-process-checkout-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['woocommerce-process-checkout-nonce'])), 'woocommerce-process_checkout')) { return; } foreach ($this->custom_fields as $field) { if (isset($field['active']) && $field['active'] === 'yes') { $field_id = 'enspireplugins_acfw_' . $field['id']; if (!empty($_POST[$field_id])) { $value = sanitize_text_field(wp_unslash($_POST[ $field_id])); update_post_meta($order_id, '_' . $field_id, $value); update_post_meta($order_id, '_' . $field['id'], $value); } } } } }