Skip to content

Commit

Permalink
Remove due date title and base fields
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadNateqi committed Nov 7, 2023
1 parent 01defc0 commit 8e13db9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 54 deletions.
13 changes: 1 addition & 12 deletions assets/js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,11 @@ jQuery( function( $ ) {
function toggle_due_date_custom_days_field() {
const due_date_value = $( '#due_date' ).val();
const due_date_custom_days = $( '#due_date_custom_days' );
const due_date_base_date = $( '#due_date_base_date' );
const due_date_title = $( '#due_date_title' );

if ( '' === due_date_value ) {
due_date_custom_days.closest( 'tr' ).hide();
due_date_base_date.closest( 'tr' ).hide();
due_date_title.closest( 'tr' ).hide();
}
else if ( 'custom' === due_date_value ) {
if ( 'custom' === due_date_value ) {
due_date_custom_days.closest( 'tr' ).show();
due_date_base_date.closest( 'tr' ).show();
due_date_title.closest( 'tr' ).show();
} else {
due_date_custom_days.closest( 'tr' ).hide();
due_date_base_date.closest( 'tr' ).show();
due_date_title.closest( 'tr' ).show();
}
}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-wcpdf-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ public function display_due_date( string $document_type, $order ): void {
return;
}

$due_date = apply_filters( "wpo_wcpdf_{$document->slug}_due_date_display", date( wcpdf_date_format( $this, 'due_date' ), $due_date_timestamp ), $due_date_timestamp, $order, $document_type );
$due_date = apply_filters( "wpo_wcpdf_due_date_display", date( wcpdf_date_format( $this, 'due_date' ), $due_date_timestamp ), $due_date_timestamp, $document_type, $order );
$due_date_title = is_callable( array( $document, 'get_due_date_title' ) ) ? $document->get_due_date_title() : __( 'Due Date:', 'woocommerce-pdf-invoices-packing-slips' );

if ( ! empty( $due_date ) ) {
Expand Down
15 changes: 3 additions & 12 deletions includes/documents/abstract-wcpdf-order-document.php
Original file line number Diff line number Diff line change
Expand Up @@ -1380,25 +1380,16 @@ public function get_due_date(): int {
}

$due_date_days = ( 'custom' === $this->settings['due_date'] ) ? intval( $this->settings['due_date_custom_days'] ?? 0 ) : absint( $this->settings['due_date'] );
$due_date_days = apply_filters( "wpo_wcpdf_{$this->slug}_due_date_days", $due_date_days, $this );
$due_date_days = apply_filters( "wpo_wcpdf_due_date_days", $due_date_days, $this->type, $this );

if ( 0 >= $due_date_days ) {
return 0;
}

if ( isset( $this->settings['due_date_base_date'] ) && 'document_date' === $this->settings['due_date_base_date'] && $this->exists() ) {
// The `get_date()` method has been used to get the date as a WC_DateTime object.
$base_date = $this->get_date( $this->get_type() );
}

if ( empty( $base_date ) ) {
$base_date = $this->order->get_date_created();
}

$base_date = apply_filters( "wpo_wcpdf_{$this->slug}_due_date_base_date", $base_date, $this );
$base_date = apply_filters( "wpo_wcpdf_due_date_base_date", $this->order->get_date_created(), $this->type, $this );
$due_date_datetime = $base_date->modify( "+$due_date_days days" );

return apply_filters( "wpo_wcpdf_{$this->slug}_due_date", $due_date_datetime->getTimestamp() ?? 0, $this );
return apply_filters( "wpo_wcpdf_due_date", $due_date_datetime->getTimestamp() ?? 0, $this->type, $this );
}

protected function add_filters( $filters ) {
Expand Down
29 changes: 0 additions & 29 deletions includes/documents/class-wcpdf-invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,35 +363,6 @@ public function get_pdf_settings_fields( $option_name ) {
'description' => __( 'Enter the number of days for the due date.', 'woocommerce-pdf-invoices-packing-slips' ),
)
),
array(
'type' => 'setting',
'id' => 'due_date_title',
'title' => 'Due date label',
'callback' => 'i18n_wrap',
'section' => $this->type,
'args' => array(
'callback' => 'text_input',
'option_name' => $option_name,
'id' => 'due_date_title',
'placeholder' => __( 'Due date:', 'woocommerce-pdf-invoices-packing-slips' ),
)
),
array(
'type' => 'setting',
'id' => 'due_date_base_date',
'title' => __( 'Due date base', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'select',
'section' => $this->type,
'args' => array(
'option_name' => $option_name,
'id' => 'due_date_base_date',
'options' => apply_filters( 'wpo_wcpdf_due_date_base_date_options', array(
'order_date' => __( 'Order date', 'woocommerce-pdf-invoices-packing-slips' ),
'document_date' => __( 'Invoice date', 'woocommerce-pdf-invoices-packing-slips' ),
), $this->slug ),
'description' => __( 'Choose the initial date from which the due date will be calculated.', 'woocommerce-pdf-invoices-packing-slips' )
)
),
array(
'type' => 'setting',
'id' => 'display_number',
Expand Down

0 comments on commit 8e13db9

Please sign in to comment.