Okay
  Public Ticket #3721148
Offers and product tables
Closed

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,281
    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,281
    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,281
    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...

  •  2,281
    WebWizards replied

    Please try adding this PHP snippet to your site: 

    https://pastecode.io/s/ug1w2xdu

    It does several things to set the minimum / step to 0.1 (instead of 1 which is the default). It can also be changed to a lower value like 0.01 in the snippet if needed.

     

    Do you still see any issues with that? If so, it would help if you can share details / screenshots. We can also work on this directly if you can help share a site or staging site login.

  • Sarah replied

    Thank you for this...it's now allowing me to add those decimal quantities, however, the mini cart and checkout seems to round the values to a whole number

  •  2,281
    WebWizards replied

    Regarding rounding in the mini-cart/checkout, this is a bit hard to say. I am not quite sure if it's a theme behaviour, or related to the specific checkout used (e.g. blocks vs classic, or perhaps a theme checkout like the Divi ones).

    Would it be possible to share a backend access to the site, or a staging clone site with us? It would be great if we could look at it on the site directly and try to tweak the snippet to get this to work perfectly.

     

    Kind regards,

    Stefan

  •   Sarah replied privately
  •  2,281
    WebWizards replied

    Thank you for the access details,

     

    At the moment there is an error in cart regardless of quantity:

    2584372399.png

    The error is coming from line 24 here:

    2695831586.png

    3979189713.png

    specifically related to this $product object not working (it has a 'false' value) here:

    3121583371.png

     

    I see you have some custom code there using ACF. I am not sure what the goal there is.

     

    For testing purposes, I did the following:

    -> I activated the main theme instead of the child theme, to get around that error.

    -> I added this snippet here (now deactivated): https://rjchefs2024.sagraphicswebproofs.co.uk/wp-admin/admin.php?page=wpcode-snippet-manager&snippet_id=5535

     

    When testing that way, I can set decimal quantities, and I see they do not get rounded in cart or checkout:

    https://www.loom.com/share/474bd0b5305c4457954121de4fa6ff33?sid=30055bc7-5ed5-4fd1-aa84-84e6851f5e6f

    9075183107.png

  • Sarah replied

    Your response is appreciated, but it came a little late.  I had resolved my issue with a workaround, however, I now have issues adding a particular item to cart which I didn't have before...it took 3 attempts to add Hickory Smoked Pork to the cart...no error messages on the frontend...just disappeared until "third time lucky"

  •  2,281
    WebWizards replied

    Hi again,

    Is this on a general shop page or product page? B2BKing does not control the add to cart process on these pages.

    I would suggest to check your browser console for any errors during the add to cart.

    It may also help to enable or disable AJAX add to cart: https://prnt.sc/Iy8KHRVtOhM6