WOOT - WooCommerce Active Products Tables

How to add custom column to the tables

Use hook woot_profile_extend for it.

For this in file functions.php add next code:

add_action('woot_profile_extend', function($profile, $action_name) {

    if ($action_name === 'woot_woocommerce_tables') {
      
        $profile['my_new_column'] = [
            'title' => WOOT_Vocabulary::get('My new column'),
            'order' => FALSE,
            'action' => function($post_id) {
                return 'Hello World!';
            }
        ];
    }

    return $profile;
}, 10, 2);

Using $post_id you can create any data and return it directly to the cell.


Lets review more complicated example demonstrated here. Make your attention on button “Ask Me“, click on it. As you can see this is contact form where customer can write a message to the shop manager about the product. To create it:

  • create new page and select template as “WOOT Blank Page
  • install any contact form plugin, for example wpform
  • place to new page content contact form shortcode, for example [wpforms id=”641″]
  • add next code to the functions.php file of the current WordPress theme:
    add_action('woot_profile_extend', function($profile, $action_name) {
    
        if ($action_name === 'woot_woocommerce_tables') {
          
            $profile['ask_me'] = [
                'title' => 'Ask Me',
                'order' => FALSE,
                'action' => function($post_id) {
                    return WOOT_HELPER::draw_html_item('a', [
                                'href' => 'javascript: new Popup23({iframe:"https://demo.products-tables.com/wpform-contact-ask-me/?product_id=' . $post_id . '", '
                                . 'allow:"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture", '
                                . 'title:"Ask manager about the product"});void(0);',
                                'class' => 'woot-btn'
                                    ], 'Ask Me');
                }
            ];
        }
    
        return $profile;
    }, 10, 2);
    

    Make your attention on the link “https://demo.products-tables.com/wpform-contact-ask-me” and change it to your own.

  • To fill some inputs of the contact form apply next code:
    add_filter('wp_footer', function() {
    
        if (is_page(642)) {
            if (isset($_GET['product_id'])) {
                $product = WOOT_WooCommerce::get_product(intval($_GET['product_id']));
                if (is_object($product)) {
                    ?>
                    <script>
                        document.getElementById('wpforms-641-field_4').value = '<?php echo addslashes($product->get_title()) ?>';
                        document.getElementById('wpforms-641-field_2').value = "Hello, give me please more information about the product: <?php echo addslashes($product->get_title()) ?>!";
                    </script>
                    <?php
                }
            }
        }
    });

    642 – page ID where contact form placed;
    wpforms-641-field_4 – ID of the input