2017 © Pedro Peláez
 

wordpress-plugin wc-export

Export various data from WooCommerce

image

frozzare/wc-export

Export various data from WooCommerce

  • Tuesday, February 21, 2017
  • by fredrikforsmo
  • Repository
  • 1 Watchers
  • 2 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

WooCommerce Export

Build Status No Maintenance Intended, (*1)

Export various data from WooCommerce., (*2)

The plugin cames with two exporters, a customers export that will export all billing fields and a emails exporter that will export the billing email field from a order., (*3)

The are three writers built in, CSV, XML and JSON., (*4)

Installation

composer require frozzare/wc-export

Documentation

Custom export

Example of a custom export type that will export the billing_email field from a order. With query_args method you can modify the WP_Query arguments., (*5)

<?php

use Frozzare\WooCommerce\Export\Exports\Export;

class Custom_Emails extends Export {

    /**
     * Get fields that should be exported.
     *
     * @return array
     */
    public function get_fields() {
        return [
            'billing_email' => __( 'Email', 'woocommerce' )
        ];
    }

    /**
     * Modify WP Query args.
     *
     * @param  array  $args
     *
     * @return array
     */
    public function query_args( array $args ) {
        return $args;
    }
}

Then you have to add the custom export to the exporter list with wc_export_classes filter., (*6)

<?php

/**
 * Add export classes.
 *
 * @param  array $exports
 *
 * @return array
 */
add_filter( 'wc_export_classes', function ( array $exports ) {
    return array_merge( $exports, [
        'Custom emails' => '\\Custom_Emails'
    ] );
} );

Custom writer

Example of a custom export writer that will export the given data argument to render method as JSON., (*7)

<?php

use Frozzare\WooCommerce\Export\Writers\Writer;

class Custom_JSON extends Writer {

    /**
     * Get the content type.
     *
     * @var string
     */
    protected function get_content_type() {
        return 'application/json';
    }

    /**
     * Get the file extension.
     *
     * @var string
     */
    protected function get_extension() {
        return 'json';
    }

    /**
     * Render JSON file.
     *
     * @param array $data
     */
    protected function render( array $data ) {
        foreach ( $data as $index => $row ) {
            if ( ! is_array( $row ) ) {
                unset( $data[$index] );
            }
        }

        echo json_encode( $data, JSON_UNESCAPED_UNICODE );
    }
}

Then you have to add the custom writer to the writers list with wc_export_writers filter., (*8)

<?php

/**
 * Add export writer.
 *
 * @param  array $writers
 *
 * @return array
 */
add_filter( 'wc_export_writers', function ( array $writers ) {
    return array_merge( $writers, [
        'Custom JSON' => '\\Custom_JSON'
    ] );
} );

License

MIT © Fredrik Forsmo, (*9)

The Versions

21/02 2017

dev-master

9999999-dev https://github.com/frozzare/wc-export

Export various data from WooCommerce

  Sources   Download

MIT

The Requires

  • php ^5.5.9 || ^7.0

 

The Development Requires

plugin wordpress export woocommerce

20/07 2016

v1.0.0

1.0.0.0 https://github.com/frozzare/wc-export

Export various data from WooCommerce

  Sources   Download

MIT

The Requires

  • php ^5.5.9 || ^7.0

 

The Development Requires

plugin wordpress export woocommerce