'My Fancy Field', 'show' => true]; return $fields; }, 20, 1); /** * This hook lets you add custom fields the email part. Add them first with "woocommerce_admin_billing_fields". * * @param array $fields - The email part fields */ add_filter('wac_supported_fake_email_parts', function (array $fields) { $fields[] = 'custom_field_1'; //Name of the custom field to add return $fields; }, 10, 1); /** * Action that will happen after a new customer got saved. * * @param string $user_id - The user id * @param string $order_id - The id of the order */ add_action('wac_after_insert_new_customer', function ($user_id, $order_id) { //Do action }, 10, 2); /** * Action that will happen after a new customer got saved. * * @param string $user_id - The user id * @param string $order_id - The id of the order */ add_action('wac_after_insert_updated_customer', function ($user_id, $order_id) { //Do action }, 10, 2); /** * Edit user Page * This actions will modify the edit user page. */ /** * Displays the custom field in the edit user page * @param object $user - WP_User object */ add_action('edit_user_profile', function ($user) { //Note that if we use the filter "woocommerce_admin_billing_fields" to add the field, the fieldname will be changed to billing_custom_field_1 $custom_field_value = get_user_meta($user->ID, 'billing_custom_field_1', true); echo '

'; echo ''; echo '

'; }); /** * Updates the custom meta field * @param string $user_id - The user id */ add_action('edit_user_profile_update', function ($user_id) { //WordPress verifies the nonce of the user profile form before this hook $field_value = isset($_REQUEST['billing_custom_field_1']) ? sanitize_text_field(wp_unslash($_REQUEST['billing_custom_field_1'])) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ($field_value) { update_user_meta($user_id, 'billing_custom_field_1', $field_value); } }); /** * Deactivates the WooCommerce for the user with the ID 13. You can also use this hook to reactivate the sending again * @param bool $is_deactivated - If the emails are deactivated for the given user * @param int $user_id - The user id */ add_filter( 'wac_deactivate_user_emails', function($is_deactivated, $user_id){ if($user_id === 13){ return true; //Deactivates all the emails to the user } return false; //Emails wil be sent to the user as normal }, 10, 2 ); ?>