Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD: integration with PDF Invoices plugin https://woocommerce.com/pro… #2

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion inc/class-async-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function generate_zip( $order_statuses ) {
return new WP_Error( 'error', sprintf( esc_html__( 'Order from %1$s to %2$s not found.', 'woocommerce-pdf-invoices-bulk-download' ), $this->date_after, $this->date_before ) );
}

return $this->run( $orders);
return $this->run( $orders );
}

public function create_zip( $files = array(), $destination = '', $args = array(), $callback = null ) {
Expand Down Expand Up @@ -126,6 +126,10 @@ public function run( $orders ) {

} else if ( function_exists( 'wcpdf_get_document' ) ) {
$r = $this->woocommerce_pdf_invoices_packing_slips( $orders );

} else if ( defined( 'PDFPLUGINPATH' ) ) {
require_once( PDFPLUGINPATH . 'classes/class-pdf-send-pdf-class.php' );
$r = $this->woocommerce_pdf_invoice_plugin( $orders );
}

return apply_filters( 'woocommerce-pdf-invoices-bulk-download/run/after', $r, $orders, $this );
Expand Down Expand Up @@ -182,6 +186,22 @@ function( $files_to_zip ) {
} );
}

public function woocommerce_pdf_invoice_plugin( $orders ) {
$files_to_zip = array();

foreach ( $orders as $order ) {
$files_to_zip[] = WC_send_pdf::get_woocommerce_invoice( $order );
}

$archive_name = $this->get_archive_name();

return $this->create_zip(
$files_to_zip,
$archive_name,
array( 'overwrite' => true )
);
}

public function get_archive_name() {
return sprintf( 'Invoices_%s-%s.zip', $this->date_after, $this->date_before );
}
Expand Down
3 changes: 3 additions & 0 deletions woocommerce-pdf-invoices-bulk-download.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
$depends_plugins = array(
'woocommerce-pdf-invoices/bootstrap.php',
'woocommerce-pdf-invoices-packing-slips/woocommerce-pdf-invoices-packingslips.php',
'woocommerce-pdf-invoice/woocommerce-pdf-invoice.php',
);

$plugin_is_activated = false;
Expand Down Expand Up @@ -72,7 +73,9 @@ function woo_pdf_invoices_buld_download_depends_fail() {
$messages = array();
$messages[] = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( 'https://wordpress.org/plugins/woocommerce-pdf-invoices/' ), esc_html__( 'WooCommerce PDF Invoices', 'woocommerce-pdf-invoices-bulk-download' ) );
$messages[] = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( 'https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/' ), esc_html__( 'WooCommerce PDF Invoices & Packing Slips', 'woocommerce-pdf-invoices-bulk-download' ) );
$messages[] = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( 'https://woocommerce.com/products/pdf-invoices/' ), esc_html__( 'PDF Invoices', 'woocommerce-pdf-invoices-bulk-download' ) );


$html_message = sprintf( '<div class="error"><p><strong>%1$s</strong> %2$s %3$s</p></div>', esc_html__( 'WooCommerce PDF Invoices Bulk Download Extension', 'woocommerce-pdf-invoices-bulk-download' ), esc_html__( 'plugin are depends from one of plugins:', 'woocommerce-pdf-invoices-bulk-download' ), join( ', ', $messages ) );

echo wp_kses_post( $html_message );
Expand Down