Buy B2BKing
$249 $179
In this article, you can find a number of useful hooks, functions, snippets, and references to help you when working with B2BKing as a developer.
Please also check our documentation articles here: There are over 100 articles, some user-oriented and some dev-oriented, designed to help you accomplish a wide range of tasks.
The plugin has a variety of global functions that you can use anywhere on your site. These can all be found in b2bking/includes/class-b2bking-global-helper.php
Example:
Usage example:
The above example checks if the user with ID 123 is a B2B user and returns true or false (bool).
Available functions:
There are a large number of action and filter hooks in the plugin, and more are being added all the time. Therefore, this is not a complete list—just a brief overview. If you're looking for specific hooks or areas, it's best to check the code directly or get in touch with our support team.
Action hooks:
The above hooks are applied on the user profile page in the "Data collected at registration" panel.
The above hooks are applied before and after a message is sent.
Filters and their default values:
Here's how to add a phone number column:
add_action('b2bking_b2bcustomers_column_header', function(){ echo '<th>Phone Number</th>'; }); add_action('b2bking_b2bcustomers_column_footer', function(){ echo '<th>Phone Number</th>'; }); add_filter('b2bking_b2bcustomers_row_content', function($row, $user_id){ $phone = get_user_meta($user_id,'billing_phone', true); if (empty($phone)){ $phone = get_user_meta($user_id,'shipping_phone', true); if (empty($phone)){ $phone = '-'; } } $column = '<td>'.$phone.'</td>'; if (is_array($row)){ array_push($row, $phone); } else { $row.=$column; } return $row; }, 10, 2);
By default, emails for messages and quote requests go to the email configured on the admin side. To change that or add multiple emails:
add_filter('b2bking_recipient_new_message', function($recipient, $conversationid){ $recipient = '[email protected], [email protected]'; return $recipient; }, 10, 2); add_filter('b2bking_recipient_new_message_quote', function($recipient, $conversationid){ $recipient = '[email protected], [email protected]'; return $recipient; }, 10, 2);
B2BKing has a built-in "New message" email that is quite flexible and can be used with custom code to send an email in various situations. Here's how to fire an email:
do_action( 'b2bking_new_message', '[email protected]', 'Your custom message here...', get_current_user_id(), 0 );
In the above code, all that needs to be changed is the email ([email protected]) and the message.
For example, here's how to send an email to a subaccount when their account is first created:
add_action('b2bking_after_subaccount_created', function($user_id){ $user = new WP_User($user_id); do_action( 'b2bking_new_message', $user->user_email, 'Congratulations on your new account ...', get_current_user_id(), 0 ); }, 10, 1);
The above code will send them a welcome email.
Use the b2bking()->is_b2b_user($user_id) function described above.
Use b2bking()->get_user_group($user_id) to get the group ID.
Use b2bking()->get_user_group_name($user_id) to get the group name.
In B2BKing documentation, we frequently refer to a rule ID or field ID, etc. This is the post ID of a post, as all B2BKing items like rules or fields are custom post types.
To get the rule ID of a dynamic rule, go to B2BKing -> Dynamic Rules and click on the rule. The number in the URL such as ?post=123 is the ID (123 in that case).
To get the field ID of a B2BKing custom field, go to B2BKing -> Registration Fields and click on the field. The number in the URL such as ?post=45 is the ID (45 in that case).
If you're looking to show users their group and perhaps a total spent or progress made, please see this article.
If you're looking to show specific elements or content to specific groups or users only, please see this article.
If you are using third-party plugins that rely on WP roles instead of the B2BKing group, it is possible for B2BKing to sync the two. For details, please see the WP roles sync article.
To modify B2BKing emails—either their content or their styling—please see the linked article above.
If you'd like to import dynamic rules programmatically, in bulk, or via the REST API, please see the linked article above.
If you are importing users and need to set a specific user group during import, please see this article.
If you need to set B2B prices for a product programmatically, please see this article for the appropriate product meta keys.
Importantly, after doing so, you must clear caches (see below).
If you need to configure or import subaccounts programmatically, please see the linked article, which describes the user meta key structure needed.
After making any programmatic changes to rules, prices, users, etc., you should also clear B2BKing's internal caches by calling this function:
b2bking()->clear_caches_transients();
If you make programmatic changes or additions to dynamic rules, you should also call:
b2bking()->b2bking_clear_rules_caches();
If you need help with anything or have any questions, you can contact us by opening a ticket at https://webwizards.ticksy.com
Powered by BetterDocs