Okay
  Public Ticket #3721148
Offers and product tables
Open

Comments

  • Sarah started the conversation

    I have the barn2 product tables plugin as well as b2bking wholesale - I have the product tables working as I need them for normal shop/category pages, but I would like to apply the same format to the b2bking offers (using real products)...I just need to know how to query whether there is an offer(s) available for the logged in user and list these in the same format

  •  2,161
    WebWizards replied

    Hi Sarah,

    I understand that you'd like to display B2BKing offers using the Barn2 Product Table display.

    I'm afraid I don't really see a simple / straightforward way to achieve that - the main issue is that these offers are not actual WooCommerce Products, instead they are just information saved in a database. Therefore to make this work I think we need a PHP code snippet to pull the data from the database, and then somehow display it using the Barn2 table.

    We are happy to send some PHP code for pulling our plugin's offers information if it would help, but generally I believe you would need to work with a developer on a custom project in order to be able to display that info using the Barn2 table. I think their table might need some changes as well because I'm guessing their table is built to display products, but in this case the offers are not actual products.


    Kind regards,

    Stefan

  • Sarah replied

    Hi Stefan, thank you for your reply...in the b2bking settings, I have the option "Offers use actual products" selected, so I assume that means there is a link between the two somewhere...

    If you could help in any way with a php code snippet to help me with the barn2 integration, and a little more guidance on how the frontend layouts are generated in b2bking, that would be fantastic!

    I bought the barn2 plugin because of it's compatibility with your plugin because I needed customers to have a very quick shopping experience and (as they are chefs) are very particular.  So, for them, it would make a lot more sense if all shopping tables (shop, offers, bulk order form etc) looked the same layout and styling wise.

  •  2,161
    WebWizards replied

    Regarding the "Offers use actual products" setting: What this does is that it also adds the real products to the cart, as in this image:

    1899268642.png

    There is the offer being purchased (at the top, 'sweater package'), and then the products inside the offer below. This helps to make sure that for example if the site has an ERP integration, this links correctly with that, as the real products are also in the actual order (although we give them the price of 0, so only the offer is being paid for).

    The issue is with the main "offer" package product, as that is a 'helper / dynamic' product, that changes its price and name for each offer (rather than being an actual product that is distinct).



    To make an integration with the Barn2 tables plugin, maybe we could do it based on the URL that B2BKing uses when clicking 'add to cart' on an offer - to take that same URL and add it to the Barn2 table.


    I think we could start with the following code:

    add_action('wp_footer', function(){
        $user_id = get_current_user_id();
        $user = get_user_by('id', $user_id) -> user_login;
        $email = get_user_by('id', $user_id) -> user_email;
        $currentusergroupidnr = b2bking()->get_user_group($user_id);
        // Define custom query parameters
        $custom_query_args = array( 'post_type' => 'b2bking_offer',
                  'post_status' => 'publish',
                  'posts_per_page' => -1,
                  'meta_query'=> 
                        array(
                            'relation' => 'AND',
                            array(
                                'key' => 'b2bking_post_status_enabled',
                                'value' => '1',
                            ),
                            array(
                                'relation' => 'OR',
                                array(
                                    'key' => 'b2bking_group_'.$currentusergroupidnr,
                                    'value' => '1',
                                ),
                                array(
                                    'key' => 'b2bking_user_'.$user, 
                                    'value' => '1',
                                ),
                                array(
                                    'key' => 'b2bking_user_'.$email, 
                                    'value' => '1',
                                ),
                            ),
                        )
                   );
        $custom_query = new WP_Query( $custom_query_args );
        $offers = $custom_query->posts;
        foreach ($offers as $offer){
            $offer_title = $offer->post_title;
            $offer_id = $offer->ID;
            echo $offer_title;
            ?>
            <button class="b2bking_offer_add" value="<?php echo esc_attr($offer_id); ?>" type="button">
            <?php echo apply_filters('b2bking_offer_add_to_cart_button', esc_html__('Add to Cart','b2bking')); ?></button><br>
            <?php
        }
    });
    

    This code gets all offers of the current user, displays them, and displays an "add to cart" button. 

    It results in this kind of output:

    5252458753.png


    Now I am not sure if the Barn2 table has any way to display their table programmatically / with PHP, in a way that would allow us to integrate the above. If you have access to their support, it would be great if you could ask them about that. 



  • Sarah replied

    I have a meat product where I have the minimum quantity set to zero and increments of 0.1 (we're selling by weight with this product, but that's not important). I had to set the minimum to 0 because when I put 0.1, om the front end it defaulted to 1.1.  However, if you try to add 0.5 of the product to basket, for example, it says "Please enter a quantity greater than 0. "

  •  2,161
    WebWizards replied

    Hi Sarah,

    Glad to assist,

    I'd like to make sure I'm understanding it correctly: Are you looking to set this in B2BKing offers, or the B2BKing order form, or just generally for the site?

    WooCommerce by default does not support quantities such as 0.1 so you would need a larger code snippet to enable that on your site in general. Do you already have something like a plugin or custom code for that, or is this what you're looking to implement right now?

    I think we have some snippets we can share to help implement it in general on the site, but it would be great if you can let us know where you're at with it so far.

     

    Kind regards,

    Stefan

     

  • Sarah replied

    Generally for the site really...with the B2BKing plugin, it will allow me to enter a decimal quantity, but trying to add to cart, it doesn't like it...