2017-05-10 16:22:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Admin View: Product Export
|
2017-11-07 08:24:39 +00:00
|
|
|
*
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Admin\Export
|
2017-05-10 16:22:08 +00:00
|
|
|
*/
|
2017-11-07 08:24:39 +00:00
|
|
|
|
2017-05-10 16:22:08 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
2017-05-12 14:03:00 +00:00
|
|
|
|
|
|
|
wp_enqueue_script( 'wc-product-export' );
|
2017-05-12 14:26:53 +00:00
|
|
|
|
2018-01-09 09:33:10 +00:00
|
|
|
$exporter = new WC_Product_CSV_Exporter();
|
2017-05-10 16:22:08 +00:00
|
|
|
?>
|
|
|
|
<div class="wrap woocommerce">
|
2017-05-12 19:40:54 +00:00
|
|
|
<h1><?php esc_html_e( 'Export Products', 'woocommerce' ); ?></h1>
|
2017-05-10 16:22:08 +00:00
|
|
|
|
2017-05-17 13:22:41 +00:00
|
|
|
<div class="woocommerce-exporter-wrapper">
|
|
|
|
<form class="woocommerce-exporter">
|
|
|
|
<header>
|
|
|
|
<span class="spinner is-active"></span>
|
|
|
|
<h2><?php esc_html_e( 'Export products to a CSV file', 'woocommerce' ); ?></h2>
|
|
|
|
<p><?php esc_html_e( 'This tool allows you to generate and download a CSV file containing a list of all products.', 'woocommerce' ); ?></p>
|
|
|
|
</header>
|
2017-05-19 12:25:03 +00:00
|
|
|
<section>
|
|
|
|
<table class="form-table woocommerce-exporter-options">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<th scope="row">
|
|
|
|
<label for="woocommerce-exporter-columns"><?php esc_html_e( 'Which columns should be exported?', 'woocommerce' ); ?></label>
|
|
|
|
</th>
|
|
|
|
<td>
|
|
|
|
<select id="woocommerce-exporter-columns" class="woocommerce-exporter-columns wc-enhanced-select" style="width:100%;" multiple data-placeholder="<?php esc_attr_e( 'Export all columns', 'woocommerce' ); ?>">
|
|
|
|
<?php
|
2017-11-07 08:24:39 +00:00
|
|
|
foreach ( $exporter->get_default_column_names() as $column_id => $column_name ) {
|
|
|
|
echo '<option value="' . esc_attr( $column_id ) . '">' . esc_html( $column_name ) . '</option>';
|
|
|
|
}
|
2017-05-19 12:25:03 +00:00
|
|
|
?>
|
|
|
|
<option value="downloads"><?php esc_html_e( 'Downloads', 'woocommerce' ); ?></option>
|
|
|
|
<option value="attributes"><?php esc_html_e( 'Attributes', 'woocommerce' ); ?></option>
|
|
|
|
</select>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th scope="row">
|
|
|
|
<label for="woocommerce-exporter-types"><?php esc_html_e( 'Which product types should be exported?', 'woocommerce' ); ?></label>
|
|
|
|
</th>
|
|
|
|
<td>
|
|
|
|
<select id="woocommerce-exporter-types" class="woocommerce-exporter-types wc-enhanced-select" style="width:100%;" multiple data-placeholder="<?php esc_attr_e( 'Export all products', 'woocommerce' ); ?>">
|
|
|
|
<?php
|
2017-11-07 08:24:39 +00:00
|
|
|
foreach ( wc_get_product_types() as $value => $label ) {
|
|
|
|
echo '<option value="' . esc_attr( $value ) . '">' . esc_html( $label ) . '</option>';
|
|
|
|
}
|
2017-05-19 12:25:03 +00:00
|
|
|
?>
|
|
|
|
<option value="variation"><?php esc_html_e( 'Product variations', 'woocommerce' ); ?></option>
|
|
|
|
</select>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2018-07-23 09:59:01 +00:00
|
|
|
<tr>
|
|
|
|
<th scope="row">
|
|
|
|
<label for="woocommerce-exporter-category"><?php esc_html_e( 'Which product category should be exported?', 'woocommerce' ); ?></label>
|
|
|
|
</th>
|
|
|
|
<td>
|
2018-08-07 14:58:39 +00:00
|
|
|
<select id="woocommerce-exporter-category" class="woocommerce-exporter-category wc-enhanced-select" style="width:100%;" multiple data-placeholder="<?php esc_attr_e( 'Export all categories', 'woocommerce' ); ?>">
|
2018-07-23 09:59:01 +00:00
|
|
|
<?php
|
2019-11-27 20:08:56 +00:00
|
|
|
$categories = get_categories(
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'product_cat',
|
|
|
|
'hide_empty' => false,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
foreach ( $categories as $category ) {
|
2018-08-07 14:58:39 +00:00
|
|
|
echo '<option value="' . esc_attr( $category->slug ) . '">' . esc_html( $category->name ) . '</option>';
|
|
|
|
}
|
2018-07-23 09:59:01 +00:00
|
|
|
?>
|
2020-06-03 10:40:05 +00:00
|
|
|
</select>
|
2018-07-23 09:59:01 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
2017-05-19 12:25:03 +00:00
|
|
|
<tr>
|
|
|
|
<th scope="row">
|
|
|
|
<label for="woocommerce-exporter-meta"><?php esc_html_e( 'Export custom meta?', 'woocommerce' ); ?></label>
|
|
|
|
</th>
|
|
|
|
<td>
|
|
|
|
<input type="checkbox" id="woocommerce-exporter-meta" value="1" />
|
|
|
|
<label for="woocommerce-exporter-meta"><?php esc_html_e( 'Yes, export all custom meta', 'woocommerce' ); ?></label>
|
|
|
|
</td>
|
|
|
|
</tr>
|
Add product export row action hook
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;
}
```
2017-12-20 19:13:10 +00:00
|
|
|
<?php do_action( 'woocommerce_product_export_row' ); ?>
|
2017-05-19 12:25:03 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<progress class="woocommerce-exporter-progress" max="100" value="0"></progress>
|
|
|
|
</section>
|
2017-05-17 13:22:41 +00:00
|
|
|
<div class="wc-actions">
|
2017-11-07 08:27:25 +00:00
|
|
|
<button type="submit" class="woocommerce-exporter-button button button-primary" value="<?php esc_attr_e( 'Generate CSV', 'woocommerce' ); ?>"><?php esc_html_e( 'Generate CSV', 'woocommerce' ); ?></button>
|
2017-05-17 13:22:41 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2017-05-10 16:22:08 +00:00
|
|
|
</div>
|