Skip to content

Commit

Permalink
Add product export row action hook
Browse files Browse the repository at this point in the history
having this hook is possible to actually use the woocommerce_product_export_product_query_args filter

```
add_action('woocommerce_product_export_row', 'export_custom_product');
add_filter( 'woocommerce_product_export_product_query_args', 'export_product_query_args');

// https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
add_filter( 'woocommerce_product_data_store_cpt_get_products_query', 'handle_custom_query_var', 10, 2 );

function export_custom_product() {
  $args = [
    'show_option_all' =>  'Custom',
    'taxonomy'        =>  'pa_custom',
    'name'            =>  'custom',
    'orderby'         =>  'name',
    'order'           => 'ASC',
    'selected'        =>  isset($_REQUEST['custom']) ? $_REQUEST['custom'] : '',
    'show_count'      =>  true,
    'hide_empty'      =>  true,
    'menu_order'      => false
  ];
  ?>
  <tr>
    <th scope="row">
      <label for="custom">Filter by Custom</label>
    </th>
    <td>
      <?php wp_dropdown_categories($args); ?>
    </td>
  </tr>
  <?php
}

function export_product_query_args($args) {
  $args['custom'] = 'default';

  if ( ! empty( $_POST['form'] ) ) {
    $values = explode('=', $_POST['form']);
    if('custom' === $values[0]) {
      $args['custom'] = wp_unslash( $values[1] );
    }
  }

  return $args;
}

function handle_custom_query_var( $query, $query_vars ) {
  if ( ! empty( $query_vars['custom'] ) ) {
    $query['tax_query'][] = array(
      'taxonomy' => 'pa_ custom',
      'field' => 'id',
      'terms' => esc_attr( $query_vars['custom'] )
    );
  }

  return $query;
}
```
  • Loading branch information
AdamQuadmon committed Dec 20, 2017
1 parent 906efe1 commit 865efa3
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions includes/admin/views/html-admin-page-product-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<label for="woocommerce-exporter-meta"><?php esc_html_e( 'Yes, export all custom meta', 'woocommerce' ); ?></label>
</td>
</tr>
<?php do_action( 'woocommerce_product_export_row' ); ?>
</tbody>
</table>
<progress class="woocommerce-exporter-progress" max="100" value="0"></progress>
Expand Down

0 comments on commit 865efa3

Please sign in to comment.