Visser Labs – WooCommerce Plugins
  1. Home
  2. Knowledge Base
  3. Custom Login for WooCommerce
  4. Available hooks and filters in Custom Login for WooCommerce

Available hooks and filters in Custom Login for WooCommerce

You want customers to land on a specific page after they log in, or you need to add a link or a script to the login page. Custom Login for WooCommerce gives you hooks for both, so you don’t have to edit plugin files. It also has a REST API endpoint that reads and updates the plugin’s settings from code.

This article covers the clwc_login_redirect filter, the clwc_after_login_form and clwc_login_footer actions, and the /settings REST API endpoint. It also lists three smaller hooks in a short table. Setting up the login page itself is covered in Getting started with Custom Login for WooCommerce.

This is a developer reference. It assumes you’re comfortable adding PHP through a custom plugin or your child theme’s functions.php. If hooks are new to you, start with the WordPress Plugin Handbook on hooks.

Prerequisites

RequirementDetails
PluginCustom Login for WooCommerce 1.0.3 or later, installed and active
WooCommerceVersion 6.0 or later, installed and active
AccessA way to add PHP code, such as a custom plugin or a child theme
REST API accessAn account with the manage_woocommerce capability for the REST API endpoint

How the hooks fit into the login page

The plugin serves your /login page from its own standalone template. That template doesn’t load your theme’s header or footer, and it doesn’t call wp_head() or wp_footer(). So a callback added to wp_head or wp_footer never runs on this page. Use the plugin’s own hooks below instead.

Keep in mind that the redirect filter runs on the form submission, while the two actions run when the login page is displayed.

Filter: clwc_login_redirect

This filter changes where a customer goes right after a successful login. It doesn’t run when a login fails.

apply_filters( 'clwc_login_redirect', $redirect_to, $user );
ParameterTypeDescription
$redirect_tostringThe URL the customer is about to be sent to
$userWP_UserThe account that just logged in

Return the URL you want. The starting value of $redirect_to is the redirect_to value passed to the login page, for example yourstore.com/login/?redirect_to=.... If there isn’t one, it’s your WooCommerce My account page URL.

Here’s what happens after your callback returns:

  1. WooCommerce’s own woocommerce_login_redirect filter runs next. Any callback on that filter sees your result and can change it again.
  2. The plugin checks the final URL. If it points to another domain that WordPress doesn’t allow, the plugin sends the customer to My account instead.
  3. The plugin redirects the customer.

Because woocommerce_login_redirect runs after clwc_login_redirect, another plugin on that filter can override your redirect. If your redirect seems to be ignored, check for other plugins that hook into woocommerce_login_redirect.

Example: send shop managers to the dashboard

add_filter( 'clwc_login_redirect', function ( $redirect_to, $user ) {
	if ( in_array( 'shop_manager', (array) $user->roles, true ) ) {
		return admin_url();
	}

	return $redirect_to;
}, 10, 2 );

The 10 is the callback’s priority, and the 2 tells WordPress your callback accepts two parameters. Without the 2, you don’t receive $user.

Both actions let you print your own HTML on the login page. Neither one passes any parameters, so your callback needs no arguments. Output your content with echo.

ActionWhere it fires
clwc_after_login_formDirectly after the closing </form> tag, still inside the login form panel. Content appears under the form.
clwc_login_footerAfter the whole two-panel layout, near the end of the page. Content isn’t inside either panel.

Example: add a link under the login form

add_action( 'clwc_after_login_form', function () {
	echo '<p><a href="' . esc_url( home_url( '/become-a-customer/' ) ) . '">Need an account? Apply here.</a></p>';
} );

Example: add a line of text to the page footer

add_action( 'clwc_login_footer', function () {
	echo '<p style="text-align:center;">Need help? Call us on 1300 000 000.</p>';
} );

clwc_login_footer fires outside the form panel, so your own CSS decides where the content appears. For content that belongs with the form, use clwc_after_login_form.

Other hooks on the login page

These hooks are smaller and less common. They work the same way as the actions and filter above.

HookTypeWhat it does
clwc_logout_redirectFilterChanges where customers go after they log out. Receives the default URL, which is /login/ with ?logged_out=true added, and returns the URL you want.
clwc_login_headActionFires inside the page’s <head> tag, after the plugin’s styles. Use it to add a stylesheet or meta tag.
clwc_login_enqueue_scriptsActionFires near the end of the page. Use it to enqueue scripts for the login page.

The login form also fires WooCommerce’s standard login hooks: woocommerce_login_form_start, woocommerce_login_form, and woocommerce_login_form_end. That’s why most CAPTCHA and security plugins that work on the WooCommerce login form also work here.

REST API: settings endpoint

The plugin has one REST API endpoint for its settings. It lets you read the current settings or update them from code, for example when you set up many stores from one script.

/wp-json/clwc/v1/settings
MethodWhat it does
GETReturns all settings, plus the list of rotation_items
POSTUpdates the settings you send and returns all settings

Who can use it

Both methods need a logged-in account with the manage_woocommerce capability. That includes administrators and shop managers. Anyone else gets a 401 or 403 response.

For a request from the browser while you’re logged in, send the X-WP-Nonce header with a wp_rest nonce. For a request from outside WordPress, use an application password with basic authentication.

Read the settings

curl -u "admin:APPLICATION_PASSWORD" https://yourstore.com/wp-json/clwc/v1/settings

The response is a JSON object. Any setting you haven’t saved yet comes back with its default value, except logo_url, which is missing from the response until you save a logo URL.

Update the settings

Send a JSON body with only the fields you want to change. Fields you leave out stay as they are.

curl -X POST -u "admin:APPLICATION_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"template":"template-2","button_bg":"#e11d48","login_heading":"Welcome back"}' \
  https://yourstore.com/wp-json/clwc/v1/settings

From the browser, you can use wp.apiFetch in the same way:

wp.apiFetch( {
	path: '/clwc/v1/settings',
	method: 'POST',
	data: { login_button_text: 'Sign in' },
} );

The plugin cleans every value before it saves it. A value of the wrong kind is skipped or saved as empty, and the request still succeeds.

FieldsAccepted values and handling
Color fields: left_panel_bg, left_panel_text, right_panel_bg, right_panel_text, button_bg, button_text, button_hover_bg, link_color, link_hover_color, input_border, input_focus, promo_button_bg, promo_button_text_color, promo_button_hover_bg, promo_button_borderA hex color such as #3b82f6. Anything else is saved as empty.
URL fields: logo_url, promo_button_urlA valid URL. The plugin cleans it as a URL before saving.
templateOne of template-1, template-2, template-3, template-4, template-5. Other values are ignored.
promo_enabled, enable_rotationyes or no. Other values are ignored.
mobile_promo_displayhide or stack. Other values are ignored.
Text fields: login_heading, email_label, password_label, remember_label, login_button_text, lost_password_text, promo_heading, promo_button_textPlain text. HTML tags are removed.
promo_contentText with basic HTML, such as <br>, <p>, and <strong>. Unsafe HTML is removed.
rotation_itemsA list of items. Each item can have heading, content, button_text, button_url, and image_url. Sending this field replaces the whole saved list.

Fields that aren’t in the table are ignored. Also, rotation_items replaces the whole saved list each time you send it, so include every item you want to keep.

Troubleshooting

The REST API returns a 401 or 403 error
The request isn’t logged in as an account with the manage_woocommerce capability. Check that your application password belongs to an administrator or shop manager. For requests from the browser, check that you send a valid X-WP-Nonce header.
My clwc_login_redirect callback runs, but customers still go to the wrong page
Another plugin on woocommerce_login_redirect is changing the URL after yours. Also check that the URL belongs to your own site. The plugin sends customers to My account when the final URL points to a domain WordPress doesn’t allow.
My callback on clwc_login_redirect doesn’t receive $user
Your add_filter() call needs 10, 2 at the end, so WordPress passes both parameters to your function.
A color I sent through the REST API saved as empty
The plugin only accepts hex colors such as #3b82f6 or #fff. Color names like red and values like rgb(0,0,0) are saved as empty.
My code on wp_head or wp_footer doesn’t run on the login page
The login page doesn’t call those hooks. Use clwc_login_head for the <head> tag, and clwc_login_footer or clwc_login_enqueue_scripts for the end of the page.

Frequently asked questions

Do these hooks work on the standard WooCommerce login form?
No. They fire only on the plugin’s own login page. The standard WooCommerce login form keeps using the WooCommerce hooks, such as woocommerce_login_redirect.
Can a shop manager use the REST API endpoint?
Yes. The endpoint checks for the manage_woocommerce capability, and shop managers have it by default.
Do the hooks need an activated license?
No. The hooks and the REST API endpoint don’t check your license. The license key is used for plugin updates.
Where do I add the code?
Add it to a small custom plugin or your child theme’s functions.php. Don’t add it to the plugin’s own files, because plugin updates overwrite them.

Need help?

Custom Login for WooCommerce is a premium plugin, so if you need help with a specific customization, open a support ticket and our team can point you to the right hook for your use case.

Was this article helpful?

Related Articles

Resources & Help