Public Ticket #2885110

Regarding REST API

Closed
Comments
6 Tickets 1
spkinbox started the conversation 5 years ago on October 1, 2021 at 12:32pm

Hi, 
I'm using B2B for woo commerce, it's working properly. I need to use this in Flutter Mobile App, where I can get the code to display b2b price in mobile when customer logged in, and also I purchased b2b credit limit addon. I want to display the customer's credit limit on the app dashboard. So pls support me, where I can find those data via REST API. Pls, send me any documentation for Rest API.

2,762
KingsPlugins replied 5 years ago on October 2, 2021 at 3:41pm

Hi there,

Thank you for purchasing our B2BKing plugin and Credit addon,

B2BKing does not have its own API, but all data is stored as WP or WooCommerce metadata.


1."where I can get the code to display b2b price in mobile when customer logged in"

Group price metadata can be found here: https://b2bkingplugin.com/docs/release-1-8-0-price-lists-csv-import-export-pricing-in-the-product-page/

The meta keys are

b2bking_regular_product_price_group_GROUPID

b2bking_sale_product_price_group_GROUPID  

Replace "GROUPID" with the ID of the group you are setting prices for.

Example:

If you set product meta b2bking_regular_product_price_group_222 = 199 , this means that B2B users in the group with ID 222 will see the product's price as $199.

I think for example you can get this price by using the WooCommerce products API: https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product

2. To get the customer's credit limit:

Normally, in PHP, we use the following functions to get this data:

// maximum credit limit
function get_user_credit_limit(){
        // Get current user
        $user_id = $this->get_user_id();
        $credit_limit = get_user_meta($user_id,'b2bking_user_credit_limit', true);
        // if not set, go to user's group credit setting
        if (!$credit_limit || empty($credit_limit)){
            $currentusergroupidnr = get_user_meta( $user_id, 'b2bking_customergroup', true );
            $credit_limit = get_post_meta($currentusergroupidnr,'b2bking_group_credit_limit', true);
        }
        // if not set, go to default credit limit setting
        if (!$credit_limit || empty($credit_limit)){
            $credit_limit = get_option('b2bking_default_credit_limit_setting', 0);
        }
        return intval($credit_limit);
    }
// consumed credit
function get_user_consumed_balance(){
        // Get current user
        $user_id = $this->get_user_id();
        $consumed_balance = get_user_meta($user_id,'b2bking_user_credit_consumed_balance', true);
        if (!$consumed_balance){
            $consumed_balance = 0;
        }
        return $consumed_balance;
    }
// credit still available
    function get_user_available_credit(){
        // Get current user
        $user_id = $this->get_user_id();
        $credit_limit = $this->get_user_credit_limit();
        $consumed_balance = $this->get_user_consumed_balance();
        $available_credit = $credit_limit - $consumed_balance;
        return $available_credit;
    }

For API, I think you would need to get the user meta values, possibly with the  WordPress API.

Kind Regards,

Stefan

1

Sign In