From 5c2fdf017b4209e392994c1668803d1b74b15a90 Mon Sep 17 00:00:00 2001 From: Lucas Gama Date: Wed, 14 Aug 2024 10:09:56 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20melhoria=20na=20mensagem=20de=20notifica?= =?UTF-8?q?=C3=A7=C3=A3o=20das=20taxas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/js/admin.js | 3 --- src/assets/js/notification.js | 7 +++++++ src/utils/FrontendFilesLoader.php | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/assets/js/notification.js diff --git a/src/assets/js/admin.js b/src/assets/js/admin.js index d74f7f46..0cd90135 100644 --- a/src/assets/js/admin.js +++ b/src/assets/js/admin.js @@ -128,7 +128,4 @@ jQuery(document).ready(function ($) { } }); - const newTextOrder = document.querySelector('.wc-order-data-row'); - newTextOrder.append('O valor pode variar de acordo com a Taxa da assinatura') - }); \ No newline at end of file diff --git a/src/assets/js/notification.js b/src/assets/js/notification.js new file mode 100644 index 00000000..86f83d63 --- /dev/null +++ b/src/assets/js/notification.js @@ -0,0 +1,7 @@ +jQuery(document).ready(function ($) { + 'use strict'; + if (orderData.hasSubscription) { + const newTextOrder = document.querySelector('.wc-order-data-row'); + newTextOrder.append('O valor final pode variar com base nas condições da assinatura.'); + } +}); diff --git a/src/utils/FrontendFilesLoader.php b/src/utils/FrontendFilesLoader.php index 7b571a51..ce4eb1c3 100644 --- a/src/utils/FrontendFilesLoader.php +++ b/src/utils/FrontendFilesLoader.php @@ -6,6 +6,7 @@ die(); exit; // Exit if accessed directly } +use WC_Subscriptions_Product; class FrontendFilesLoader { @@ -13,6 +14,7 @@ function __construct() { add_action('wp_enqueue_scripts', array($this, 'frontendFiles')); add_action('admin_enqueue_scripts', array($this, 'adminFiles')); add_action('wp_enqueue_scripts', [$this, 'enqueue_inputmask_scripts']); + add_action('add_meta_boxes', array($this, 'check_for_subscription_in_order')); } public static function adminFiles() @@ -96,6 +98,7 @@ public static function enqueueCreditCardScripts() ); wp_enqueue_script('vindi_woocommerce_brands_js'); } + public function enqueue_inputmask_scripts() { $cdnInput = 'https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/5.0.8/jquery.inputmask.min.js'; @@ -107,4 +110,28 @@ public function enqueue_inputmask_scripts() }); '); } + + public function check_for_subscription_in_order() { + global $post; + + if ($post->post_type === 'shop_order' || $post->post_type === 'shop_subscription') { + $order = wc_get_order($post->ID); + $has_subscription = false; + $subscriptions_product = new WC_Subscriptions_Product(); + + foreach ($order->get_items() as $item_id => $item) { + if ($subscriptions_product->is_subscription($item->get_product())) { + $has_subscription = true; + break; + } + } + + wp_register_script('notification-js', plugins_url('/assets/js/notification.js', plugin_dir_path(__FILE__)), array('jquery'), VINDI_VERSION, true); + wp_enqueue_script('notification-js'); + + wp_localize_script('notification-js', 'orderData', array( + 'hasSubscription' => $has_subscription + )); + } + } }