Skip to content

Commit

Permalink
Merge branch 'main' into psr4-strauss-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Oct 1, 2024
2 parents f91a482 + 59be479 commit daa9b2e
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 78 deletions.
118 changes: 111 additions & 7 deletions assets/css/settings-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,15 @@ body.woocommerce_page_wpo_wcpdf_options_page {
margin-bottom: 4em;
}

#wpo-wcpdf-preview-wrapper input#due_date_days {
text-align: right;
}

#wpo-wcpdf-preview-wrapper input#due_date_days:disabled {
background-color: #eaeaea;
color: #999;
}

sup.wcpdf_beta {
background-color: #51266b;
color: white;
Expand Down Expand Up @@ -1120,7 +1129,8 @@ div.upgrade-table-description a,
font-size: 0.8em;
}

#upgrade-table .upgrade-links a.upgrade_button {
#upgrade-table .upgrade-links a.upgrade_button,
#plugin-recommendations a.upgrade_button {
display: inline-block;
background: white;
padding: 1em 3em 1em 2em;
Expand All @@ -1131,7 +1141,8 @@ div.upgrade-table-description a,
position: relative;
}

#upgrade-table .upgrade-links a.upgrade_button:after {
#upgrade-table .upgrade-links a.upgrade_button:after,
#plugin-recommendations a.upgrade_button:after {
content: ' \2192'; /* ASCII code for right arrow */
display: block;
position: absolute;
Expand All @@ -1140,18 +1151,92 @@ div.upgrade-table-description a,
transition: 0.5s;
}

#upgrade-table .upgrade-links a.upgrade_button:hover:after {
#upgrade-table .upgrade-links a.upgrade_button:hover:after,
#plugin-recommendations a.upgrade_button:hover:after {
right: 1.1em;
font-weight: bold;
}


#upgrade-table .upgrade-links a.upgrade_button:focus,
#upgrade-table .upgrade-links a.upgrade_button:hover {
#upgrade-table .upgrade-links a.upgrade_button:hover,
#plugin-recommendations a.upgrade_button:focus,
#plugin-recommendations a.upgrade_button:hover {
background: #6e1edc;
color: #fcfbf7;
}

#plugin-recommendations {
border-radius: 8px;
background-color: #f1e9fc;
padding: 4em 3em;
}

#plugin-recommendations .card-container {
max-width: 1100px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 3em;
padding: 2em 0;
}

#plugin-recommendations .recommendation-card {
margin-top: 0;
border-radius: 6px;
background-color: white;
box-shadow: 0 0 25px -10px rgba(0,0,0,0.2);
box-sizing: border-box;
font-size: 15px;
overflow: hidden;
transition: 0.2s;
}

#plugin-recommendations .recommendation-card:nth-child(n+4) {
display: none;
}

#plugin-recommendations .recommendation-card:hover {
scale: 1.02;
}

#plugin-recommendations .recommendation-card.currently-installed {
opacity: 0.5;
}

#plugin-recommendations .recommendation-card .card-content{
padding: 0 4em 3em 2em;
}

#plugin-recommendations .recommendation-card img {
width: 100%;
}

#plugin-recommendations .recommendation-card h5 {
text-align: left;
font-size: 1.4em;
line-height: 1.3em;
font-weight: bold;
margin: 1em 0;
}

#plugin-recommendations .recommendation-card p {
text-align: left;
padding-bottom: 10px;
}

#plugin-recommendations .recommendation-card a.upgrade_button {
margin: 0;
}

#plugin-recommendations .recommendation-card span.currently-installed {
font-size: 0.7em;
color: white;
background-color: #6e1edc;
padding: 1em 2em;
border-radius: 12px;
margin: 0;
display: inline-block;
}

@media screen and (max-width: 1100px) {
#upgrade-table {
font-size: 1em;
Expand All @@ -1173,21 +1258,36 @@ div.upgrade-table-description a,
#upgrade-table td.feature-label span.description {
padding-top: 6px;
}

#plugin-recommendations .card-container {
grid-gap: 2em;
}
}

@media screen and (max-width: 968px) {
#plugin-recommendations .card-container {
grid-template-columns: repeat(1, 1fr);
padding-right: 40%;
}
}

@media screen and (max-width: 767px) {
#upgrade-table td.feature-label span.description {
display: none;
}

#upgrade-table th:not(.last),
#upgrade-table td:not(.last) {
width: 20%;
}

#upgrade-table td.first {
width: 40%;
}

#plugin-recommendations .card-container {
padding-right: 0;
}
}

@media screen and (max-width: 649px) {
Expand Down Expand Up @@ -1223,4 +1323,8 @@ div.upgrade-table-description a,
#upgrade-table .upgrade-links a:after {
display: none;
}

#plugin-recommendations .card-container {
justify-content: center;
}
}
2 changes: 1 addition & 1 deletion assets/css/settings-styles.min.css

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ jQuery( function( $ ) {
'delay': 200
} );

$( '#wpo-wcpdf-preview-wrapper #due_date' ).change( function() {
const $due_date_checkbox = $( '#wpo-wcpdf-preview-wrapper #due_date' );
const $due_date_days_input = $( '#wpo-wcpdf-preview-wrapper #due_date_days' );

if ( $due_date_checkbox.is( ':checked' ) ) {
$due_date_days_input.prop( 'disabled', false );
} else {
$due_date_days_input.prop( 'disabled', true );
}
} ).trigger( 'change' );

//----------> Preview <----------//
// objects
let $previewWrapper = $( '#wpo-wcpdf-preview-wrapper' );
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-script.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function __construct() {
add_action( 'woocommerce_admin_order_actions_end', array( $this, 'add_listing_actions' ) );

if ( $this->invoice_columns_enabled() ) { // prevents the expensive hooks below to be attached. Improves Order List page loading speed
add_filter( 'manage_woocommerce_page_wc-orders_columns', array( $this, 'add_invoice_columns' ), 999 ); // WC 7.1+
add_filter( 'manage_woocommerce_page_wc-orders_columns', array( $this, 'add_invoice_columns' ), 200 ); // WC 7.1+ (we lowered the priority to 200 to make sure it works with Admin Columns plugin: https://www.admincolumns.com/)
add_action( 'manage_woocommerce_page_wc-orders_custom_column', array( $this, 'invoice_columns_data' ), 10, 2 ); // WC 7.1+
add_filter( 'manage_woocommerce_page_wc-orders_sortable_columns', array( $this, 'invoice_columns_sortable' ) ); // WC 7.1+
add_filter( 'woocommerce_shop_order_list_table_sortable_columns', array( $this, 'add_invoice_column_to_sortable_columns' ) );
add_filter( 'woocommerce_order_list_table_prepare_items_query_args', array( $this, 'adjust_order_list_query_args' ) );

add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_invoice_columns' ), 999 );
add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_invoice_columns' ), 200 ); // (we lowered the priority to 200 to make sure it works with Admin Columns plugin: https://www.admincolumns.com/)
add_action( 'manage_shop_order_posts_custom_column', array( $this, 'invoice_columns_data' ), 10, 2 );
add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'invoice_columns_sortable' ) );
add_action( 'pre_get_posts', array( $this, 'sort_orders_by_numeric_invoice_number' ) );
Expand Down
18 changes: 8 additions & 10 deletions includes/Documents/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,16 @@ public function get_pdf_settings_fields( $option_name ) {
'type' => 'setting',
'id' => 'due_date',
'title' => __( 'Display due date', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'select',
'callback' => 'checkbox_text_input',
'section' => $this->type,
'args' => array(
'option_name' => $option_name,
'id' => 'due_date',
'options' => apply_filters( 'wpo_wcpdf_due_date_options', array(
'' => __( 'No', 'woocommerce-pdf-invoices-packing-slips' ),
'1' => __( '1 day', 'woocommerce-pdf-invoices-packing-slips' ),
'7' => __( '7 days', 'woocommerce-pdf-invoices-packing-slips' ),
'30' => __( '30 days', 'woocommerce-pdf-invoices-packing-slips' ),
), $this->type ),
'description' => __( 'Displays a due date below the order data.', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'due_date',
/* translators: number of days */
'text_input_wrap' => __( '%s days', 'woocommerce-pdf-invoices-packing-slips' ),
'text_input_size' => 3,
'text_input_id' => 'due_date_days',
'text_input_default' => 30,
)
),
array(
Expand Down
35 changes: 28 additions & 7 deletions includes/Documents/OrderDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,16 @@ public function due_date_title() {
echo $this->get_due_date_title();
}

/**
* Prints the due date.
*
* @return void
*/
public function due_date(): void {
$due_date_timestamp = $this->get_due_date();
echo apply_filters( "wpo_wcpdf_{$this->slug}_formatted_due_date", date_i18n( wcpdf_date_format( $this, 'due_date' ), $due_date_timestamp ), $due_date_timestamp, $this );
}

/*
|--------------------------------------------------------------------------
| Data setters
Expand Down Expand Up @@ -1463,23 +1473,34 @@ public function get_number_store_year( $table_name ) {
* @return int
*/
public function get_due_date(): int {
$due_date = $this->get_setting( 'due_date' );
$due_date = $this->get_setting( 'due_date' );
$due_date_days = $this->get_setting( 'due_date_days' );

if ( empty( $this->order ) || empty( $due_date ) ) {
if ( empty( $this->order ) || empty( $due_date ) || empty( $due_date_days ) ) {
return 0;
}

$due_date_days = apply_filters( 'wpo_wcpdf_due_date_days', $due_date, $this->type, $this );
$due_date_days = apply_filters( 'wpo_wcpdf_due_date_days', $due_date_days, $this );

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

$base_date = apply_filters( 'wpo_wcpdf_due_date_base_date', $this->order->get_date_created(), $this->type, $this );
$due_date_datetime = clone $base_date;
$due_date_datetime = $due_date_datetime->modify( "+$due_date_days days" );
$document_creation_date = $this->get_date( $this->get_type(), $this->order ) ?? new \WC_DateTime( 'now', new \DateTimeZone( 'UTC' ) );
$base_date = apply_filters( 'wpo_wcpdf_due_date_base_date', $document_creation_date, $this->get_type(), $this );
$due_date_datetime = clone $base_date;
$due_date_datetime = $due_date_datetime->modify( "+$due_date_days days" );

return apply_filters( 'wpo_wcpdf_due_date', $due_date_datetime->getTimestamp() ?? 0, $this->type, $this );
return apply_filters( 'wpo_wcpdf_due_date', $due_date_datetime->getTimestamp() ?? 0, $this );
}

/**
* Check if the document has a due date.
*
* @return bool
*/
public function has_due_date(): bool {
return $this->get_due_date() > 0;
}

protected function add_filters( $filters ) {
Expand Down
27 changes: 24 additions & 3 deletions includes/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function __construct() {
add_filter( 'woocommerce_webhook_topics', array( $this, 'wc_webhook_topics' ) );
add_action( 'wpo_wcpdf_save_document', array( $this, 'wc_webhook_trigger' ), 10, 2 );

add_action( 'wpo_wcpdf_after_order_data', array( $this, 'display_due_date' ), 10, 2 );
// Add due date via action hook for legacy templates
add_action( 'wpo_wcpdf_after_order_data', array( $this, 'display_due_date_table_row' ), 10, 2 );

add_action( 'wpo_wcpdf_delete_document', array( $this, 'log_document_deletion_to_order_notes' ) );
}
Expand Down Expand Up @@ -1601,16 +1602,36 @@ public function wc_webhook_trigger( $document, $order ) {
}

/**
* Display due date table row in the order data section for legacy templates.
*
* @param null|string $document_type
* @param null|\WC_Order|\WC_Order_Refund $order
* @param null|\WC_Abstract_Order $order
*
* @return void
*/
public function display_due_date( string $document_type = null, $order = null ): void {
public function display_due_date_table_row( ?string $document_type = null, ?\WC_Abstract_Order $order = null ): void {
if ( empty( $order ) || empty( $document_type ) ) {
return;
}

$current_template_path = explode( '/', WPO_WCPDF()->settings->get_template_path() );
$current_template = end( $current_template_path );
$premium_templates = array( 'Simple Premium', 'Modern', 'Business' );

// Return if the Simple template is selected. Due date is displayed through template.
if ( 'Simple' === $current_template ) {
return;
}

// Return if the Updated Premium Template is selected. Due date is displayed through template.
if (
function_exists( 'WPO_WCPDF_Templates' ) &&
version_compare( WPO_WCPDF_Templates()->version, '2.21.9', '>' ) &&
in_array( $current_template, $premium_templates, true )
) {
return;
}

$document = wcpdf_get_document( $document_type, $order );

if ( ! $document ) {
Expand Down
5 changes: 0 additions & 5 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,6 @@ public function settings_page() {
$default_tab = apply_filters( 'wpo_wcpdf_settings_tabs_default', ! empty( $settings_tabs['general'] ) ? 'general' : key( $settings_tabs ) );
$active_tab = isset( $_GET[ 'tab' ] ) ? sanitize_text_field( $_GET[ 'tab' ] ) : $default_tab;
$active_section = isset( $_GET[ 'section' ] ) ? sanitize_text_field( $_GET[ 'section' ] ) : '';
$bundle = $this->upgrade ? $this->upgrade->bundle_is_active() : false;

if ( $bundle ) {
unset( $settings_tabs['upgrade'] );
}

include( WPO_WCPDF()->plugin_path() . '/views/settings-page.php' );
}
Expand Down
Loading

0 comments on commit daa9b2e

Please sign in to comment.