add_action('admin_enqueue_scripts', function($hook) { if ($hook === 'post.php' && isset($_GET['post']) && get_post_type($_GET['post']) === 'shop_coupon') { add_filter('woocommerce_coupon_data_tabs', 'add_coupon_usage_tab'); add_action('woocommerce_coupon_data_panels', 'add_coupon_usage_tab_content'); // اسکریپت Ajax wp_enqueue_script('coupon-usage-ajax', plugin_dir_url(__FILE__) . 'coupon-usage.js', array('jquery'), '1.0', true); wp_localize_script('coupon-usage-ajax', 'couponUsageData', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('load_coupon_usage_data'), 'coupon_id' => $_GET['post'], )); } }); function add_coupon_usage_tab($tabs) { $tabs['used_by'] = array( 'label' => __('استفاده‌ شده', 'woocommerce'), 'target' => 'used_by_coupon_data', 'class' => '', 'priority' => 90, ); return $tabs; } function add_coupon_usage_tab_content($coupon) { echo '
'; echo '

در حال بارگذاری سفارش‌ها...

'; echo '
'; } // Ajax handler add_action('wp_ajax_load_coupon_usage_data', function() { check_ajax_referer('load_coupon_usage_data', 'nonce'); $coupon_id = intval($_POST['coupon_id']); $coupon = new WC_Coupon($coupon_id); if (!is_a($coupon, 'WC_Coupon')) { wp_send_json_error('کوپن معتبر نیست.'); } $coupon_code = strtolower($coupon->get_code()); $args = array( 'limit' => -1, 'status' => array('wc-completed'), 'return' => 'ids', ); $orders = wc_get_orders($args); $matched_orders = []; foreach ($orders as $order_id) { $order = wc_get_order($order_id); if (!$order) continue; $used_coupons = $order->get_coupon_codes(); foreach ($used_coupons as $used_coupon) { if (strtolower($used_coupon) === $coupon_code) { $matched_orders[] = $order; break; } } } ob_start(); if (!empty($matched_orders)) { echo '

سفارش‌های تکمیل‌شده با این کوپن

'; echo '
'; echo ''; echo ''; echo ''; foreach ($matched_orders as $order) { $order_id = $order->get_id(); $customer_name = $order->get_formatted_billing_full_name(); $email = $order->get_billing_email(); $phone = $order->get_billing_phone(); $order_date = method_exists($order, 'get_date_created') && $order->get_date_created() ? convert_date_to_jalali($order->get_date_created()) : '-'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
شماره سفارشنام مشتریایمیلشماره موبایلتاریخ
#' . $order_id . '' . esc_html($customer_name) . '' . esc_html($email) . '' . esc_html($phone) . '' . esc_html($order_date) . '
'; echo '
'; } else { echo '

هیچ سفارش تکمیل‌شده‌ای با این کوپن یافت نشد.

'; } wp_send_json_success(ob_get_clean()); }); تجهیزات صوتی تصویری - فروشگاه اینترنتی دیجیسام تک
لغو پیش بارگیری
369 محصول
مرتب‌سازی:

تجهیزات صوتی تصویری

error:
📢 کد تخفیف 10% برای خرید اول از سایت با کد 👈 DIGIOFF10 🎁
واتساپ
کارشناس فروش
تلفن
با کارشناسان در تماس باشید
اینستاگرام
ایمیل فروشگاه
info@digisamtech.ir
تلگرام
Digisamuser@