Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save TanvirHasan19/02b64b119f7f65214b660419a02fec4c to your computer and use it in GitHub Desktop.

Select an option

Save TanvirHasan19/02b64b119f7f65214b660419a02fec4c to your computer and use it in GitHub Desktop.
WooCommerce Wholesale Lead Capture Plugin - Hooks Reference

WooCommerce Wholesale Lead Capture Plugin - Hooks Reference

Registration Form Hooks

Action Hooks (do_action)

  1. before_registration_form

    • Location: includes/class-wwlc-shortcode.php:298
    • Parameters: $registration_form_fields (array)
    • Description: Fires before the registration form is rendered
    • Use case: Add content or modify fields before form display
  2. after_registration_form

    • Location: includes/class-wwlc-shortcode.php:356
    • Parameters: $registration_form_fields (array)
    • Description: Fires after the registration form is rendered
    • Use case: Add content after the form
  3. wwlc_initialize_registration_form

    • Location: includes/class-wwlc-forms.php:337
    • Parameters: None
    • Description: Fires when the registration form is initialized (after nonce and honeypot fields)
    • Use case: Add custom fields or scripts at form start
  4. wwlc_end_registration_form

    • Location: includes/class-wwlc-forms.php:350
    • Parameters: $options (array) - Shortcode options
    • Description: Fires at the end of the registration form (before closing form tag)
    • Use case: Add hidden fields or scripts at form end
  5. wwlc_action_before_create_wholesale_lead

    • Location: includes/class-wwlc-user-account.php:453
    • Parameters: $user_data (array), $auto_generated_password (bool), $password (string)
    • Description: Fires before creating a new wholesale lead
    • Use case: Validate or modify user data before user creation
  6. wwlc_action_after_create_wholesale_lead

    • Location: includes/class-wwlc-user-account.php:501
    • Parameters: $new_lead (WP_User object)
    • Description: Fires after a wholesale lead is created
    • Use case: Perform actions after user creation
  7. wwlc_new_user_email

    • Location: includes/class-wwlc-user-account.php:726
    • Parameters: $user_id (int), $user_pass (string)
    • Description: Fires when sending new user email
    • Use case: Customize email behavior

Filter Hooks (apply_filters)

  1. wwlc_registration_form_fields

    • Location: includes/class-wwlc-shortcode.php:349
    • Parameters: $registration_form_fields (array)
    • Description: Filters the registration form fields array before rendering
    • Use case: Modify, add, or remove form fields
    • Important for VAT ID: Use this to add custom validation attributes to your VAT ID field
  2. wwlc_sanitized_user_data

    • Location: woocommerce-wholesale-lead-capture.functions.php:576
    • Parameters: $sanitized_data (array), $raw_user_data (array), $context (string)
    • Description: Filters sanitized user data after processing
    • Use case: Modify sanitized data before saving
  3. wwlc_create_user_response_data

    • Location: includes/class-wwlc-user-account.php:554
    • Parameters: $response (array)
    • Description: Filters the response data after user creation attempt
    • Use case: Modify success/error messages or add custom data
  4. wwlc_stop_registering

    • Location: includes/class-wwlc-user-account.php:456
    • Parameters: $stop (bool), $user_data (array)
    • Description: Allows preventing user registration
    • Use case: Add custom validation to block registration if validation fails
    • Important for VAT ID: Use this to validate VAT ID via VIES before allowing registration
  5. wwlc_fail_user_login

    • Location: includes/class-wwlc-user-account.php:461
    • Parameters: $message (string), $status (string)
    • Description: Filters the error message when registration is stopped
    • Use case: Customize error messages
  6. wwlc_inline_notice

    • Location: includes/class-wwlc-user-account.php:416, 539, 547
    • Parameters: $message (string), $status (string - 'success' or 'fail')
    • Description: Filters inline notice messages
    • Use case: Customize success/error messages

Field Label Filters

These filters allow you to modify field labels:

  • wwlc_filter_first_name_field_form_label
  • wwlc_filter_last_name_field_form_label
  • wwlc_filter_phone_field_form_label
  • wwlc_filter_email_field_form_label
  • wwlc_filter_username_form_label
  • wwlc_filter_company_field_form_label
  • wwlc_filter_country_field_form_label
  • wwlc_filter_address1_field_form_label
  • wwlc_filter_address1_field_form_placeholder
  • wwlc_filter_address2_field_form_label
  • wwlc_filter_address2_field_form_placeholder
  • wwlc_filter_city_field_form_label
  • wwlc_filter_city_field_form_placeholder
  • wwlc_filter_state_field_form_label
  • wwlc_filter_state_field_form_placeholder
  • wwlc_filter_postcode_field_form_label
  • wwlc_filter_postcode_field_form_placeholder
  • wwlc_filter_password_field_form_label

Form Control Filters

  • wwlc_filter_registration_form_register_control - Filter the register button HTML
  • wwlc_filter_registration_form_login_control - Filter the login link HTML
  • wwlc_filter_registration_form_lost_password_control - Filter the lost password link HTML
  • wwlc_filter_terms_and_condition_text - Filter terms and conditions text
  • wwlc_filter_privacy_policy_text - Filter privacy policy text

Login Form Hooks

  • wwlc_filter_login_form_action - Filter login form action URL
  • wwlc_filter_login_field_label_username - Filter username label
  • wwlc_filter_login_field_label_password - Filter password label
  • wwlc_filter_login_field_label_remember_me - Filter remember me label
  • wwlc_filter_login_field_label_login - Filter login button label
  • wwlc_login_form_args - Filter login form arguments
  • wwlc_before_login_form - Action hook before login form
  • wwlc_login_forms - Action hook for login form elements (used for reCAPTCHA)

User Management Action Hooks

  • wwlc_action_before_approve_user - Before user approval
  • wwlc_action_after_approve_user - After user approval
  • wwlc_action_before_reject_user - Before user rejection
  • wwlc_action_after_reject_user - After user rejection
  • wwlc_action_before_activate_user - Before user activation
  • wwlc_action_after_activate_user - After user activation
  • wwlc_action_before_deactivate_user - Before user deactivation
  • wwlc_action_after_deactivate_user - After user deactivation
  • wwlc_action_auto_approve_user - When user is auto-approved

User Management Filters

  • wwlc_login_user_when_auto_approve - Filter whether to auto-login user when auto-approved
  • wwlc_login_redirect_url - Filter login redirect URL
  • wwlc_filter_logout_redirect_url - Filter logout redirect URL
  • wwlc_wholesale_lead_logout_redirect - Filter logout redirect URL
  • wwlc_remove_user_after_rejection - Filter whether to remove user after rejection
  • wwlc_registration_success_message - Filter registration success message
  • wwlc_registration_status - Filter registration status
  • wwlc_always_display_message_after_registration - Filter whether to always show message after registration

Custom Fields Hooks

  • wwlc_user_registration_form_fields - Filter all registration form fields
  • wwlc_user_registration_custom_fields - Filter custom fields only
  • wwlc_manage_user_controls - Filter user management controls
  • wwlc_allowed_user_roles - Filter allowed user roles for viewing custom fields
  • wwlc_blacklist_field_attribute_wpml_translate - Filter field attributes to exclude from WPML translation
  • wwlc_show_custom_fields_on_order_details - Filter whether to show custom fields on order details

Registration Form Status Filters

  • wwlc_registration_form_loaded - Filter whether registration form is loaded
  • wwlc_login_form_loaded - Filter whether login form is loaded
  • wwlc_upgrade_account - Filter whether to show upgrade account page

Other Useful Filters

  • wwlc_required_plugins - Filter required plugin dependencies
  • wwlc_registration_allowed_roles - Filter allowed roles for registration
  • wwlc_redirect_page_url - Filter redirect page URLs
  • enable_login_page_recaptcha - Filter whether to enable reCAPTCHA on login page
  • wwlc_sanitized_user_data - Filter sanitized user data

WooCommerce Integration Hooks

The plugin also uses standard WooCommerce hooks:

  • woocommerce_form_field_text - Filter text field output
  • woocommerce_form_field_recaptcha - Filter reCAPTCHA field output
  • woocommerce_form_field_file - Filter file field output
  • woocommerce_form_field_url - Filter URL field output
  • woocommerce_form_field_hidden - Filter hidden field output
  • woocommerce_form_field_wwlc_password - Filter password field output
  • woocommerce_form_field_wwlc_checkbox - Filter checkbox field output
  • woocommerce_form_field_radio - Filter radio field output

Recommended Hooks for VIES VAT ID Validation

  1. wwlc_stop_registering — Use to validate VAT ID via VIES API and prevent registration if invalid
  2. wwlc_registration_form_fields — Use to add custom validation attributes or modify the VAT ID field
  3. wwlc_action_before_create_wholesale_lead — Use to validate VAT ID before user creation
  4. wwlc_sanitized_user_data — Use to sanitize/validate VAT ID data format
  5. wwlc_create_user_response_data — Use to add custom error messages if VAT ID validation fails

Example Implementation Approach

// Validate VAT ID via VIES before registration
add_filter( 'wwlc_stop_registering', function( $stop, $user_data ) {
    if ( isset( $user_data['your_vat_id_field'] ) ) {
        $vat_id = $user_data['your_vat_id_field'];
        // Perform VIES validation
        if ( ! your_vies_validation_function( $vat_id ) ) {
            return true; // Stop registration
        }
    }
    return $stop;
}, 10, 2 );

// Add custom error message
add_filter( 'wwlc_fail_user_login', function( $message, $status ) {
    if ( $status === 'vat_validation_failed' ) {
        return 'Invalid VAT ID. Please check your VAT number.';
    }
    return $message;
}, 10, 2 );

This list covers the hooks available in the WooCommerce Wholesale Lead Capture plugin for implementing VIES VAT ID validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment