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

Tweak: improves the templates number/date functions #660

Merged
merged 8 commits into from
Nov 27, 2023
Merged
16 changes: 16 additions & 0 deletions includes/documents/abstract-wcpdf-order-document-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,10 @@ public function get_formatted_item_price ( $item, $type, $tax_display = '' ) {
return $item_price;
}

/**
* Legacy function (v3.7.2 or inferior)
MohamadNateqi marked this conversation as resolved.
Show resolved Hide resolved
* Use $this->get_number() or $this->get_formatted_number() instead.
*/
public function get_invoice_number() {
// Call the woocommerce_invoice_number filter and let third-party plugins set a number.
// Default is null, so we can detect whether a plugin has set the invoice number
Expand All @@ -1175,10 +1179,18 @@ public function get_invoice_number() {
}
}

/**
* Legacy function (v3.7.2 or inferior)
* Use $this->number( 'invoice' ) instead.
*/
public function invoice_number() {
echo $this->get_invoice_number();
}

/**
* Legacy function (v3.7.2 or inferior)
* Use $this->get_date() or $this->get_formatted_date() instead.
*/
public function get_invoice_date() {
if ( $invoice_date = $this->get_date('invoice') ) {
return $invoice_date->date_i18n( wcpdf_date_format( $this, 'invoice_date' ) );
Expand All @@ -1187,6 +1199,10 @@ public function get_invoice_date() {
}
}

/**
* Legacy function (v3.7.2 or inferior)
* Use $this->date( 'invoice' ) instead.
*/
public function invoice_date() {
echo $this->get_invoice_date();
}
Expand Down
40 changes: 40 additions & 0 deletions includes/documents/abstract-wcpdf-order-document.php
alexmigf marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,38 @@ public function get_data( $key, $document_type = '', $order = null, $context = '
public function get_number( $document_type = '', $order = null, $context = 'view' ) {
return $this->get_data( 'number', $document_type, $order, $context );
}

public function get_formatted_number( $document_type ) {
alexmigf marked this conversation as resolved.
Show resolved Hide resolved
$number = $this->get_number( $document_type );

if ( $number ) {
return $number->get_formatted();
} else {
return '';
}
}

public function number( $document_type ) {
echo $this->get_formatted_number( $document_type );
}

public function get_date( $document_type = '', $order = null, $context = 'view' ) {
return $this->get_data( 'date', $document_type, $order, $context );
}

public function get_formatted_date( $document_type ) {
$date = $this->get_date( $document_type );

if ( $date ) {
return $date->date_i18n( wcpdf_date_format( $this, 'document_date' ) );
} else {
return '';
}
}

public function date( $document_type ) {
echo $this->get_formatted_date( $document_type );
}

public function get_notes( $document_type = '', $order = null, $context = 'view' ) {
return $this->get_data( 'notes', $document_type, $order, $context );
Expand All @@ -524,17 +552,29 @@ public function get_number_title() {
$number_title = sprintf( __( '%s Number:', 'woocommerce-pdf-invoices-packing-slips' ), $this->title );
return apply_filters( "wpo_wcpdf_{$this->slug}_number_title", $number_title, $this );
}

public function number_title() {
echo $this->get_number_title();
}

public function get_date_title() {
/* translators: %s: document name */
$date_title = sprintf( __( '%s Date:', 'woocommerce-pdf-invoices-packing-slips' ), $this->title );
return apply_filters( "wpo_wcpdf_{$this->slug}_date_title", $date_title, $this );
}

public function date_title() {
echo $this->get_date_title();
}

public function get_due_date_title() {
$due_date_title = __( 'Due Date:', 'woocommerce-pdf-invoices-packing-slips' );
return apply_filters( "wpo_wcpdf_{$this->slug}_due_date_title", $due_date_title, $this );
}

public function due_date_title() {
echo $this->get_due_date_title();
}

/*
|--------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions templates/Simple/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
<?php do_action( 'wpo_wcpdf_before_order_data', $this->get_type(), $this->order ); ?>
<?php if ( isset( $this->settings['display_number'] ) ) : ?>
<tr class="invoice-number">
<th><?php echo $this->get_number_title(); ?></th>
<td><?php $this->invoice_number(); ?></td>
<th><?php $this->number_title(); ?></th>
<td><?php $this->number( $this->get_type() ); ?></td>
</tr>
<?php endif; ?>
<?php if ( isset( $this->settings['display_date'] ) ) : ?>
<tr class="invoice-date">
<th><?php echo $this->get_date_title(); ?></th>
<td><?php $this->invoice_date(); ?></td>
<th><?php $this->date_title(); ?></th>
<td><?php $this->date( $this->get_type() ); ?></td>
</tr>
<?php endif; ?>
<tr class="order-number">
Expand All @@ -82,10 +82,10 @@
<th><?php _e( 'Order Date:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
<td><?php $this->order_date(); ?></td>
</tr>
<?php if ( $payment_method = $this->get_payment_method() ) : ?>
<?php if ( $this->get_payment_method() ) : ?>
<tr class="payment-method">
<th><?php _e( 'Payment Method:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
<td><?php echo $payment_method; ?></td>
<td><?php $this->payment_method(); ?></td>
</tr>
<?php endif; ?>
<?php do_action( 'wpo_wcpdf_after_order_data', $this->get_type(), $this->order ); ?>
Expand Down
Loading