• Good morning, Is it possible to extract the items to show in the table via a custom query?

    In practice I should extract the products that correspond to the skus present in a custom mysql table relating to the logged in user.

    Thank’s

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WC Product Table

    (@wcproducttable)

    Hi Marco,

    Thank you for your query about my plugin. I will be happy to answer.

    Yes, what you want can be easily achieved with the plugin hooks. Please see the plugin’s docs > developer API > wcpt_query_args filter hook.

    You can use this filter hook to modify the product query arguments used by the table. In this case you might want to use the post__in key to add your custom set of post ids.

    See a code example below:

    // custom query for product table
    add_filter( 'wcpt_query_args', 'custom_query_args' );
    function custom_query_args( $query_args ) {
      $table_data = wcpt_get_table_data(); // table data
      if( $table_data['id'] == '123' ){ // target table id
        $post__in = array(); // add your custom post ids
        $query_args['post__in'] = $post__in; // insert your custom arg
      }
    
      return $query_args;
    }

    Notes on the above code:

    • We are hooking into the product query before the table prints the products as we wish to modify the query args.
    • First we check if we are currently working on the table we want to target by looking up current table data and settings a condition against its id.
    • Then we replace the post__in key of the query args with our own array of product ids and return it to the table.

    I hope this information helps! Please feel free to write in if you have further questions.

    Useful plugin links: Tutorials | Documentation | FAQs

    Regards,
    Kartik

    Plugin Author WC Product Table

    (@wcproducttable)

    Hi! As I have not heard back from your in a while I am assuming this requirement is resolved and closing this topic. Please feel free to reopen if you have further questions on this or any other topic related to the plugin!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom product query’ is closed to new replies.