Public Ticket #4580270

Need correct hook for new customer group creation

Closed
Comments
1 Ticket
Susan started the conversation 2 months ago on August 20, 2026 at 9:27pm

I am using B2BKing version 5.2.40 and need to automatically apply WooCommerce product-category visibility to newly created B2BKing customer groups.

I need a hook that fires when a new B2BKing customer group is created, and I need the newly created group's ID passed to the hook.

The B2BKing AI help tool suggested:

b2bking_after_group_created

but I tested it on my live 5.2.40 installation and it did not fire or produce any change.

Can you please confirm the exact action hook in B2BKing 5.2.40 that fires immediately after a customer group is created, and provide its exact arguments?

I will use it to set WooCommerce product-category term meta for the new group.

My intended visibility structure is:

Standard categories: visible to all guests, B2C users, existing B2B groups, and automatically to every new B2B group.

Brokerage categories: all are children of the WooCommerce Broker Partners category and must remain restricted to their corresponding B2BKing group.

2,762
KingsPlugins replied 2 months ago on August 21, 2026 at 12:00am

Hi Susan,

Thank you for purchasing our plugin!

 

Unfortunately the `b2bking_after_group_created` hook doesn't exist - the AI tool hallucinated that one. Sorry about the confusion. If something isn't in our documentation, the AI doesn't have any special insider info.

That said, you can use the WordPress `save_post` hook for the B2BKing group post type:

add_action('save_post_b2bking_group', function( $group_id, $post, $update ) {
// Your code here
}, 10, 3);

This fires whenever a group is saved, so you'd want to add a metadata check to ensure your code only runs the first time (on creation, not on every update).

 

I'd be happy to try and put together a code snippet for you to set visibility automatically. For the standard categories part, that seems straightforward - make them visible to all new groups.

For the brokerage categories though, I'd need a bit more clarity: how would the code know which brokerage category corresponds to which B2BKing group? Is there a naming convention or some other link between them?

Also, how many groups do you currently have (or expect to have)? Feel free to share more about your setup and goals - there might be a simpler way to achieve what you're looking for.

Kind regards,
Stefan

1
1 Ticket
Susan replied 2 months ago on August 21, 2026 at 2:07am

Yes, please! That would be super awesome if you could create a snippet to use; thank you!

Essentially, we have a site that sells marketing products (business cards, letterhead, etc) to individual land sales agents (b2c) as well as to companies that are our "broker partners". A broker partner is a land sales company that signs up with us to get a private collection of products designed just for that company, that all of their agents can order from, and a discount for their agents on all of our products. 

Our "standard" products include all of the main categories like business cards, license plates, truck magnets, etc, etc. All of these products in all of these categories will always be shown to all site visitors (guests, b2c, and any/all current and future b2b in any group). 

Our "brokerage" products are products that we have designed for one specific brokerage/company for their agents to be able to order from (using their specific branding and colors, etc.). We include some business cards, letterhead, etc., all specific to this one company only. No one should be able to see any of the products in these categories at all, ever, except the logged-in people who work for this company (and are thus in this company's b2bking group). Brokerage A can see all standard products and all Brokerage A products (in Brokerage A product category), and NO products from any other Brokerage. Brokerage B can see all standard products and all Brokerage B products (in Brokerage B product category) but no products from any other Brokerage.

===

The "brokerage" product categories correspond to their associated b2bking group in that they have the same slug.  

When a brokerage partners with us, I create a new b2b group with that company's name, and I create a new product category under the parent category of "broker partners" in woocommerce. 

Example:

B2BKing group:

Midwest Land Group

WooCommerce category:

Midwest Land Group

WooCommerce category URL:

/product-category/broker-partners/midwest-land-group/

The "broker-partners" product category is empty and not associated with a business, I just included it as a parent category to be able to target the sub categories which are each of my broker-partner's products. 

===

Currently, when we add a new broker partner (adding a b2bking group and related products in same named product category), we have to edit every existing "standard" product category, manually. This is to enable the new people in the new group to view the standard products that everyone else sees. 

We want the code to make it so when a new group is saved for the first time, it is configured to be able to see all of the existing product categories (EXCEPT the ones below /broker-partner/ as these are all the "brokerage" product categories. The brokerage categories will continue to be individually manually configured so that only their corresponding brokerage group can see them.)

===

wishlist:

- When a new B2BKing customer group is created (not every time an existing group is edited), automatically add that new group's visibility to all standard WooCommerce product categories.
- Exclude the Broker Partners category and all of its descendants.
- Include any necessary B2BKing cache/transient clearing.
- Be safe to use in a WordPress Code Snippets plugin

===

I hope I'm not being confusing! Let me know if you have any questions!! 

Kind regards,
Susan

2,762
KingsPlugins replied 1 month ago on August 22, 2026 at 2:03pm

Hi Susan,

Thanks for explaining this!

I've put together a snippet for this - you can find it here: https://pastecode.io/s/nekbzeww

Here's what it does:

- Runs only when a B2BKing group is published for the first time (not on every edit/update)
- Makes all standard WooCommerce product categories visible to the new group (excluding the broker-partners category and all its descendants)

After creating the group, you'd just need to edit the corresponding Brokerage category and manually enable that specific group.

 

You can add the snippet to your theme's functions.php or a code snippets plugin. I'd suggest testing it first by creating a temporary test group to make sure everything works as expected.

If you run into any issues, let me know. I can also take a look directly on the site if you can share a backend login to the site or a staging clone.

Kind regards,
Stefan

1
1 Ticket
Susan replied 1 month ago on August 22, 2026 at 3:56pm

YES! Thank you SO much! This is exactly what I needed and it's the last piece in the puzzle for my site. Thank you thank you thank you!

- Susan

2,762
KingsPlugins replied 1 month ago on August 23, 2026 at 4:45pm

Hi Susan,

That's really great to hear :)

If you run into any issues with it or need help with anything else, please reach out anytime.

By the way, if you have a moment, we'd really appreciate a quick rating for the plugin - it's a big help.

Kind regards,
Stefan

Sign In