| 1 |
<?php |
| 2 |
|
| 3 |
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; |
| 4 |
use MailerLite\Includes\Classes\Process\OrderProcess; |
| 5 |
|
| 6 |
/** |
| 7 |
* Register meta boxes |
| 8 |
*/ |
| 9 |
function woo_ml_register_meta_boxes() |
| 10 |
{ |
| 11 |
|
| 12 |
$screen = wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() |
| 13 |
? wc_get_page_screen_id( 'shop-order' ) |
| 14 |
: 'shop_order'; |
| 15 |
|
| 16 |
add_meta_box( |
| 17 |
'woo-ml-order', |
| 18 |
'<span class="woo-ml-icon"></span> ' . __('MailerLite', 'woo-mailerlite'), |
| 19 |
'woo_ml_order_meta_box_output', |
| 20 |
$screen, |
| 21 |
'side', |
| 22 |
'low' |
| 23 |
); |
| 24 |
} |
| 25 |
|
| 26 |
add_action('add_meta_boxes', 'woo_ml_register_meta_boxes'); |
| 27 |
|
| 28 |
/** |
| 29 |
* Outputs the content of the meta box |
| 30 |
*/ |
| 31 |
function woo_ml_order_meta_box_output($post) |
| 32 |
{ |
| 33 |
|
| 34 |
wp_nonce_field(basename(__FILE__), 'woo_ml_order_meta_box_nonce'); |
| 35 |
|
| 36 |
$order = ($post instanceof WP_Post) ? wc_get_order($post->ID) : $post; |
| 37 |
|
| 38 |
$order_id = $order->get_id(); |
| 39 |
|
| 40 |
$icon_yes = '<span class="dashicons dashicons-yes" style="color: #00A153;right: 7px;position: absolute;"></span>'; |
| 41 |
$icon_no = '<span class="dashicons dashicons-no-alt" style="color: #a00;right: 7px;position: absolute;"></span>'; |
| 42 |
?> |
| 43 |
<?php $subscribe = OrderProcess::getInstance()->orderCustomerSubscribe($order_id); ?> |
| 44 |
<p> |
| 45 |
<?php echo _e('Signed up for emails', |
| 46 |
'woo-mailerlite') . wc_help_tip("Customer ticked the Subscribe box at the checkout stage to receive newsletters."); ?><?php echo ($subscribe) ? $icon_yes : $icon_no; ?> |
| 47 |
</p> |
| 48 |
<?php $subscribed = OrderProcess::getInstance()->checkCustomerSubscribed($order_id); ?> |
| 49 |
<p> |
| 50 |
<?php echo _e('Subscribed to email list', |
| 51 |
'woo-mailerlite') . wc_help_tip("Customer was successfully added to the subscriber list in MailerLite."); ?><?php echo ($subscribed) ? $icon_yes : $icon_no; ?> |
| 52 |
</p> |
| 53 |
<?php $already_subscribed = OrderProcess::getInstance()->orderCustomerAlreadySubscribed($order_id); ?> |
| 54 |
<p> |
| 55 |
<?php echo _e('Previously subscribed', |
| 56 |
'woo-mailerlite') . wc_help_tip("Customer was already an existing subscriber."); ?><?php echo ($already_subscribed) ? $icon_yes : $icon_no; ?> |
| 57 |
</p> |
| 58 |
<?php $subscriber_updated = OrderProcess::getInstance()->checkOrderSubscriberUpdated($order_id); ?> |
| 59 |
<p> |
| 60 |
<?php echo _e('Updated subscriber data', |
| 61 |
'woo-mailerlite') . wc_help_tip("Checkout data including purchases and contact information was successfully updated in MailerLite."); ?><?php echo ($subscriber_updated) ? $icon_yes : $icon_no; ?> |
| 62 |
</p> |
| 63 |
<?php $order_data_submitted = OrderProcess::getInstance()->orderDataSubmitted($order_id); ?> |
| 64 |
<p> |
| 65 |
<?php echo _e('Order data submitted', |
| 66 |
'woo-mailerlite') . wc_help_tip("Order data is uploaded to MailerLite once the payment is processed."); ?><?php echo ($order_data_submitted) ? $icon_yes : $icon_no; ?> |
| 67 |
</p> |
| 68 |
<?php $order_tracking_completed = OrderProcess::getInstance()->checkOrderTracking($order_id); ?> |
| 69 |
<p> |
| 70 |
<?php echo _e('Order tracking completed', |
| 71 |
'woo-mailerlite') . wc_help_tip("All stages of the tracking process on this order have been completed."); ?><?php echo ($order_tracking_completed) ? $icon_yes : $icon_no; ?> |
| 72 |
</p> |
| 73 |
<?php |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Saves the custom meta input |
| 78 |
*/ |
| 79 |
function woo_ml_order_meta_box_save($post_id) |
| 80 |
{ |
| 81 |
|
| 82 |
// Checks save status |
| 83 |
$is_autosave = wp_is_post_autosave($post_id); |
| 84 |
$is_revision = wp_is_post_revision($post_id); |
| 85 |
$is_valid_nonce = (isset($_POST['woo_ml_order_meta_box_nonce']) && wp_verify_nonce($_POST['woo_ml_order_meta_box_nonce'], |
| 86 |
basename(__FILE__))) ? 'true' : 'false'; |
| 87 |
|
| 88 |
// Exits script depending on save status |
| 89 |
if ($is_autosave || $is_revision || ! $is_valid_nonce) { |
| 90 |
return; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
add_action('save_post', 'woo_ml_order_meta_box_save'); |