Login
Get Started

Documentación de Easy Digital Downloads

Documentación, Materiales de Referencia y Tutoriales para Easy Digital Downloads 

Clase de exportación de EDD

Resumen

El sistema de Exportación de Easy Digital Downloads proporciona un marco robusto para crear exportaciones de datos personalizadas. Esta documentación cubre la clase base Exporter y cómo implementar exportadores personalizados.

Requisitos

  • WordPress 6.2+
  • Easy Digital Downloads 3.3.8+
  • PHP 7.4+

Clase Base de Exportación

La clase Exporter se encuentra en el espacio de nombres EDD\Admin\Exports\Exporters y sirve como base para toda la funcionalidad de exportación de EDD.

Métodos Requeridos

Al extender la clase Exporter, debes implementar estos métodos abstractos:

abstract protected function get_export_type(): string;
abstract protected function get_data(): array;
abstract protected function get_data_headers(): array;
abstract protected function get_total(): int;
abstract public function set_properties( $request ): void;

Creación de un Exportador Personalizado

1. Estructura Básica

Crea una clase que extienda la clase Exporter:

<?php

/**
 * Custom Exporter class.
 */
class CustomExporter extends EDD\Admin\Exports\Exporters\Exporter {

	/**
	 * Get the export type.
	 *
	 * @return string The export type.
	 */
	protected function get_export_type(): string {
		return 'custom_export';
	}

	/**
	 * Set the properties.
	 *
	 * @param array $request The request.
	 * @return void
	 */
	public function set_properties( $request ): void {
		$this->start = isset( $request['custom-export-start'] )
			? sanitize_text_field( $request['custom-export-start'] )
			: '';
		$this->end   = isset( $request['custom-export-end'] )
			? sanitize_text_field( $request['custom-export-end'] )
			: '';
	}

	/**
	 * Get the data headers.
	 *
	 * @return array The data headers.
	 */
	protected function get_data_headers(): array {
		return array(
			'id'     => __( 'ID', 'your-text-domain' ),
			'status' => __( 'Status', 'your-text-domain' ),
		);
	}

	protected function get_data(): array {
		$data = array();
		$args = array_merge(
			array(
				'number' => $this->per_step,
				'offset' => ( $this->step * $this->per_step ) - $this->per_step,
			),
			$this->get_base_args()
		);

		// Your data retrieval logic here
		$items = edd_get_orders( $args );

		foreach ( $items as $item ) {
			$data[] = array(
				'id'     => $item->id,
				'status' => $item->status,
			);
		}

		return $data;
	}

	/**
	 * Get the total.
	 *
	 * @return int The total.
	 */
	protected function get_total(): int {
		return edd_count_orders( $this->get_base_args() );
	}

	/**
	 * Get the base args.
	 *
	 * @return array The base args.
	 */
	private function get_base_args(): array {
		$args = array();
		if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
			$args['date_query'] = $this->get_date_query();
		}
		return $args;
	}
}

2. Registro de tu Exportador

Crea una clase para manejar el registro y la visualización del formulario:

/**
 * Register the custom exporter.
 *
 * @param \EDD\Admin\Exports\Registry $registry The registry instance.
 * @return void
 */
function custom_register_export( \EDD\Admin\Exports\Registry $registry ) {
	$registry->register_exporter(
		'custom_export',
		array(
			'label'       => __( 'Custom Export', 'your-text-domain' ),
			'description' => __( 'Export custom data.', 'your-text-domain' ),
			'class'       => CustomExporter::class,
			'class_path'  => __DIR__ . '/class-custom-export.php', // Change to your export class path.
			'button'      => __( 'Export Data', 'your-text-domain' ),
		)
	);
}
add_action( 'edd_export_init', 'custom_register_export' );

/**
 * Display the custom export form.
 *
 * @param string $exporter_id The exporter ID.
 * @return void
 */
function custom_export_form( $exporter_id ) {
	if ( 'custom_export' !== $exporter_id ) {
		return;
	}

	$from_to = new \EDD\HTML\FromTo(
		array(
			'legend' => __( 'Custom Export Date', 'your-text-domain' ),
			'id'     => 'order-export',
		)
	);
	$from_to->output();
	?>
		<label for="edd_export_custom_status" class="screen-reader-text"><?php esc_html_e( 'Select Status', 'your-text-domain' ); ?></label>
		<?php
		$statuses = array();
		foreach ( edd_get_payment_statuses() as $status ) {
			if ( 'publish' === $status ) {
				continue;
			}
			$statuses[ $status ] = edd_get_payment_status_label( $status );
		}
		$select = new \EDD\HTML\Select(
			array(
				'id'               => 'edd_export_custom_status',
				'name'             => 'status',
				'show_option_all'  => __( 'All Statuses', 'your-text-domain' ),
				'show_option_none' => false,
				'selected'         => false,
				'options'          => $statuses,
			)
		);
		$select->output();
}
add_action( 'edd_export_form', 'custom_export_form' );

Con el nuevo registro de exportaciones, una vez que tengas tu clase de exportación configurada junto con tu formulario, EDD manejará el proceso de exportación automáticamente.

Fuentes:

Was this article helpful?

¡Empieza a vender hoy mismo!

Únete a más de 50.000 propietarios de tiendas inteligentes y empieza a usar la forma más fácil de vender productos digitales con WordPress.

Copyright © 2025 Sandhills Development, LLC

[universally_switcher]