Posted on

Overriding item templates of columns via a theme

Woo Product Table gives you the opportunity to Overriding templates of the columns from your theme.

You can change the contents appearance with overriding template files. Our template files could be found at woo-product-table/includes/items or if you are a pro user then you should also look at woo-product-table-pro/includes/items directory. To override via your theme simply create a directory named woo-product-table/items and copy the template files inside this directory.

Below you can see our template structure. If you want to override any of these just copy and paste in to your-theme/woo-product-table/items directory.

Overriding templates feature can give you the more flexibility to customize the Woo Product Table as per your requirement. If you need any help on this topic please let us know by creating support ticket.

Posted on

How to Add Custom Column using Action and Filter Hooks

In Woo Product Table plugin, there are lots of column already we have added. But for you maybe those are not enough. You wanted to add more custom column. That’s why I am writing this tutorial.

First we have to our custom column in default column array using wpto_default_column_arr filter.

if( !function_exists( 'new_shortcode_column' ) ){
   function new_shortcode_column( $column_array ) {
       $column_array['new_shortcode'] = 'New Shortcode';
       return $column_array;
   }
}
add_filter( 'wpto_default_column_arr', 'new_shortcode_column' );

We have added our new shortcode column to default column array. Now we need a file where we can add the content for that custom shortcode. Below this code is used in our addon plugin. Which you can find at branch New Shortcode Column – link to https://github.com/codersaiful/UltraAddons-addons/tree/new_shortcode_column

Below we have used wpto_template_loc_item_ . $keyword filter.

if( !function_exists( 'temp_file_for_new_shortcode' ) ){
    function temp_file_for_new_shortcode( $file ){
        //$file = __DIR__ . '/../file/hello.php';
        $file = $your_file_location;
        return $file;
    }
}
add_filter( 'wpto_template_loc_item_new_shortcode', 'temp_file_for_new_shortcode', 10 );

Now we need to add a input field for get the custom shortcode from user. here we have used wpto_column_setting_form_ . $keyword action to add the input field inside column area in column tab.

function input_for_new_shortcode($column_settings){
    $text = isset( $column_settings['new_shortcode']['text'] ) ? $column_settings['new_shortcode']['text'] : false;
    ?>
<input class="ua_input" name="column_settings[new_shortcode][text]" value="<?php echo esc_attr( $text ); ?>">
<?php 
}
add_action( 'wpto_column_setting_form_new_shortcode', 'input_for_new_shortcode' );

Now we have to show the shortcode content using our custom file. Here we have used hello.php

<?php
$my_shortcode = isset( $settings['text'] ) ? $settings['text'] : '';
echo do_shortcode( $settings['text'] );
Posted on

Woo Product Table Hooks: Actions and filters

Introduction: What are hooks?

Hooks in WordPress essentially allow you to change or add code without editing core files. They are used extensively throughout WordPress and WooCommerce and are very useful for developers.

There are two types of hook: actions and filters.

  • Action Hooks allow you to insert custom code at various points (wherever the hook is run).
  • Filter Hooks allow you to manipulate and return a variable which it passes (for instance a product price).

Using hooks

There are variety of ways to add your custom code to manipulate code by hooks:

Using action hooks

To execute your own code, you hook in by using the action hook do_action('action_name');. Here is where to place your code:

add_action( 'action_name', 'your_function_name' );

function your_function_name() {
// Your code
}

Using filter hooks

Filter hooks are called throughout are code using apply_filter( 'filter_name', $variable );.To manipulate the passed variable, you can do something like the following:

add_filter( 'filter_name', 'your_function_name' );

function your_function_name( $variable ) {
// Your code
return $variable;
}

With filters, you must return a value.

To learn more about options for using hooks and filters see Snippet doc section.

Example

In the example below, both action hooks and filter hooks are used. This tutorial teaches you how to change and add fields to the checkout.

  • Actions are used to:
    • Add a new field to the checkout
    • Add that new field to the order
  • Filters are used to:
    • Override the labels and placeholders of existing fields
    • Make an existing field optional while it used to be required
    • Remove existing fields

Available action hooks and filters

For details on what the action hooks and filters do, reference the Woo Product Table Hooks Reference.