Buy B2BKing
$199 $149
Here 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 do check our documentation articles here as well: There are over 100 articles, some user-oriented, some dev-oriented, designed to help you achieve a large number 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 or not 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 value:
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 = 'newemail1@gmail.com, email2@yahoo.com'; return $recipient; }, 10, 2); add_filter('b2bking_recipient_new_message_quote', function($recipient, $conversationid){ $recipient = 'newemail1@gmail.com, email2@yahoo.com'; 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@gmail.com', 'Your custom message here...', get_current_user_id(), 0 );
In the above code all that needs to be changed is the email (email@gmail.com) and the message.
For example, here's how we can 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 their 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 (the ID is 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 (the ID is 45)
If you are looking to show the user their group and perhaps a total spent or progress made, please see this article
If you're looking to show specific elements or specific content to specific groups or users only, please see this article
If you are using 3rd party plugins which use WP Role instead of the B2BKing group, it is possible for B2BKing to sync the 2. For that, please see the wp roles sync article
To modify B2BKing emails, either their content or their styling, please see the above article.
If you'd like to import dynamic rules programmatically, in bulk, or via rest api, please see the above article.
If you are importing users and you 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 such a thing, you must clear caches (See below)
If you need to configure or import subaccounts programmatically, please see this article that describes the user meta key structure needed.
After you make any programmatic change to rules, prices, users, etc, you should also clear B2BKing 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 if you have any questions, you can contact us by opening a ticket at https://webwizards.ticksy.com
Powered by BetterDocs