Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jpham93 committed Nov 1, 2022
2 parents 4167fcc + 27039e4 commit 19352fa
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
7 changes: 3 additions & 4 deletions classes/VTACosEmailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
}

/**
* @class VTACosEmailManager
* Custom class to provide email functionality to all custom classes without default WooCommerce email templates.
*/
class VTACosEmailManager {
Expand All @@ -17,7 +16,7 @@ class VTACosEmailManager {
/** @var VTACustomOrderStatus[] */
private array $no_email_statuses;

/** @var string[] hardcoded default statuses. Emails that we want to override with our custom class & templates */
/** @var string[] hardcoded default statuses. Emails that we want to override with our custom class & templates */
private array $default_order_statuses = [
'processing',
'on-hold',
Expand Down Expand Up @@ -113,8 +112,8 @@ public function send_email( int $order_id, WC_Order $order, bool $is_reminder =
try {
$order_status = VTACustomOrderStatus::get_cos_by_key($order->get_status());
$this->wc_emails = WC_Emails::instance(); // must re-initiate class to trigger custom email classes
$this->wc_emails->init(); // initiate only for custom emails...
do_action($order_status->get_email_action() . ($is_reminder ? '_reminder' : ''), $order);
$this->wc_emails->init(); // initiate only for custom emails...
do_action($order_status->get_email_action() . ( $is_reminder ? '_reminder' : '' ), $order);

} catch ( Exception $e ) {
error_log("VTACosEmailManager::send_email() error. Could not send email for Order #$order_id - $e");
Expand Down
7 changes: 3 additions & 4 deletions classes/VTACosSettingsManager.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

/**
* @class VTACostSettingsManager
* Settings manager for plugin
*/
class VTACosSettingsManager {
Expand Down Expand Up @@ -47,7 +46,7 @@ public function __construct(
* @return void
*/
public function enqueue_scripts(): void {
list('query_params' => $query_params) = get_query_params();
[ 'query_params' => $query_params ] = get_query_params();

// Settings page
$is_settings_page = in_array($this->post_type, $query_params) && in_array($this->settings_page, $query_params);
Expand Down Expand Up @@ -200,8 +199,8 @@ public function default_settings(): void {
*/
public function render_settings_page(): void {
$reorderable_statuses = $this->settings->get_reorderable_statuses();
$reminder_statuses = $this->settings->get_reminder_statuses();
include_once(plugin_dir_path(__DIR__) . '/admin/views/settings-page.php');
$reminder_statuses = $this->settings->get_reminder_statuses();
include_once( plugin_dir_path(__DIR__) . '/admin/views/settings-page.php' );
}

/**
Expand Down
10 changes: 5 additions & 5 deletions classes/VTACustomEmail.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* @title VTACustomEmail
* Extends the core WC_Email class. This email is meant to compliment VTA's Custom Order Status.
* Reminder Emails are also configured here to allow order status to have 2 emails per order status.
*
* NOTE: These should only be used for order status notifications. This email class will not work with
* forgotten passwords, new user, etc.
*/
Expand All @@ -20,15 +20,15 @@ public function __construct( VTACustomOrderStatus $order_status, bool $is_remind
$this->is_reminder = $is_reminder;

// Add email ID, title, description, heading, subject
$this->id = "custom_email_{$order_status->get_cos_key()}" . ($is_reminder ? '_reminder' : '');
$this->id = "custom_email_{$order_status->get_cos_key()}" . ( $is_reminder ? '_reminder' : '' );
$this->customer_email = true;
$this->title = "{$order_status->get_cos_name()} Email" . ($is_reminder ? ' (Reminder)' : '');
$this->title = "{$order_status->get_cos_name()} Email" . ( $is_reminder ? ' (Reminder)' : '' );
$this->description = $is_reminder
? "This is a reminder email for Order Status \"{$order_status->get_cos_name()}\""
: "This email is received when an order status is changed to \"{$order_status->get_cos_name()}\".";

$this->heading = "{$order_status->get_cos_name()}" . ($is_reminder ? ' (Reminder)' : '');
$this->subject = "{$order_status->get_cos_name()} (Order #{order_number}) - {order_date}" . ($is_reminder ? ' (Reminder)' : '');
$this->heading = "{$order_status->get_cos_name()}" . ( $is_reminder ? ' (Reminder)' : '' );
$this->subject = "{$order_status->get_cos_name()} (Order #{order_number}) - {order_date}" . ( $is_reminder ? ' (Reminder)' : '' );

// email template path
$this->template_html = $is_reminder ? 'templates/custom-reminder-email-html.php' : 'templates/custom-email-html.php';
Expand Down
13 changes: 6 additions & 7 deletions classes/VTACustomOrderStatuses.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
<?php

/**
* @class VTA Custom Order Statuses
* Main class for Post Management for "vta_order_status" CPT.
*/
class VTACustomOrderStatuses {

// PLUGIN vars
// PLUGIN vars //
private string $plugin_name, $plugin_version;

// POST vars
// POST vars //
private string $post_type = VTA_COS_CPT;
private string $meta_color_key = META_COLOR_KEY;
private string $meta_reorderable_key = META_REORDERABLE_KEY;
private string $meta_has_reminder_key = META_HAS_REMINDER_KEY;

// SETTINGS var
// SETTINGS vars //
private VTACosSettings $settings;
private string $settings_name = VTA_COS_SETTINGS_NAME;
private string $order_status_arrangement_key = ORDER_STATUS_ARRANGEMENT_KEY;

// HELP PAGE vars
// HELP PAGE vars //
private string $help_page_slug = 'vta-cos-help';

/**
Expand Down Expand Up @@ -536,10 +535,10 @@ public function register_help_page(): void {
* @return void
*/
public function render_help_page(): void {
include_once(plugin_dir_path(__DIR__) . '/admin/views/help.php');
include_once( plugin_dir_path(__DIR__) . '/admin/views/help.php' );
}

// PRIVATE METHODS
// PRIVATE METHODS //

/**
* Returns index of Order Status arrangement placement..
Expand Down
20 changes: 17 additions & 3 deletions classes/VTAWooCommerce.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

/**
* @class VTA WooCommerce Integration
* Integrates custom order statuses to core WooCommerce hooks to reflect admin settings & custom posts in this plugin.
*/
class VTAWooCommerce {
Expand Down Expand Up @@ -42,6 +41,8 @@ public function __construct( string $plugin_name, string $plugin_version, VTACos
$this->plugin_name = $plugin_name;
$this->plugin_version = $plugin_version;

$this->deprecated_options_cleanup();

$this->settings = $settings;
$this->vta_cos = $this->get_cos();
$this->pending_status_keys = $this->get_pending_cos_keys(true);
Expand Down Expand Up @@ -193,7 +194,7 @@ public function update_custom_bulk_actions( array $bulk_actions ): array {
preg_match('/edit\.php/', $path)
) {
// default bulk actions.
// Only add if it's set in current view
// Only add if it's set in current view
$bulk_action_trash = [];
$default_bulk_actions = [ 'trash', 'untrash', 'delete' ];
foreach ( $default_bulk_actions as $default_bulk_action ) {
Expand Down Expand Up @@ -330,7 +331,7 @@ private function sort_order_statuses( array $order_statuses ): array {
*/
private function get_pending_orders_count(): int {
$non_reorderable_cos = $this->get_pending_cos_keys();
$orders = wc_get_orders([ 'status' => $non_reorderable_cos ]);
$orders = wc_get_orders([ 'status' => $non_reorderable_cos, 'limit' => -1 ]);

// manually filter orders since pre_get_posts interferes with count
$filtered_orders = array_filter(
Expand Down Expand Up @@ -364,4 +365,17 @@ private function get_pending_cos_keys( bool $with_prefix = false ): array {
return array_values(array_map(fn( VTACustomOrderStatus $order_status ) => $order_status->get_cos_key($with_prefix), $filtered_cos));
}

/**
* Cleans up old Options API from past custom emails and others (no longer used)
* @return void
*/
private function deprecated_options_cleanup(): void {
delete_option('woocommerce_finishing_email_settings');
delete_option('woocommerce_special_email_settings');
delete_option('woocommerce_ready_for_pickup_email_settings');
delete_option('woocommerce_proof_ready_email_settings');
delete_option('woocommerce_proof_email_settings');
delete_option('woocommerce_ready_reminder_email_settings');
}

}
1 change: 0 additions & 1 deletion models/VTACustomOrderStatus.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

/**
* VTA Custom Order Status Class
* Encapsulates "vta_order_status" post types for easier access
*/
class VTACustomOrderStatus {
Expand Down

0 comments on commit 19352fa

Please sign in to comment.