دوربین مدار بسته
نمایش 161–200 از 685 نتیجهSorted by popularity
if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } // توابع مربوط به نمایش دکمه و فراخوانی JS (بدون تغییر) add_action( 'wp_enqueue_scripts', 'mce_enqueue_assets_v3' ); function mce_enqueue_assets_v3() { if ( is_product_category() || is_tax('store') ) { wp_enqueue_script( 'mce-button-mover', plugin_dir_url( __FILE__ ) . 'button-mover.js', array(), '3.0.0', true ); $custom_css = " #mce-download-trigger.button { width: 100%; text-align: center; margin-top: 1em; margin-bottom: 1em; box-sizing: border-box; } "; wp_add_inline_style( 'woocommerce-layout', $custom_css ); } } add_action( 'woocommerce_before_shop_loop', 'mce_print_hidden_button_v3', 5 ); function mce_print_hidden_button_v3() { if ( is_product_category() || is_tax('store') ) { $download_link = add_query_arg( 'download_product_list_v3', 'true' ); echo ''; } } // *** منطق تولید اکسل به طور کامل بازنویسی شده است *** add_action( 'template_redirect', 'mce_handle_export_request_v3' ); function mce_handle_export_request_v3() { if ( ! isset( $_GET['download_product_list_v3'] ) || $_GET['download_product_list_v3'] !== 'true' ) { return; } if ( ! is_product_category() && ! is_tax('store') ) { return; } if (ob_get_level()) ob_end_clean(); $current_term = get_queried_object(); $file_name = 'price-list-' . $current_term->slug . '-' . date('Y-m-d') . '.csv'; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="' . $file_name . '"'); header('Pragma: no-cache'); header('Expires: 0'); // دریافت محصولات (این بخش بدون تغییر است) $args = [ 'post_type' => 'product', 'posts_per_page' => -1, 'tax_query' => [[ 'taxonomy' => $current_term->taxonomy, 'field' => 'term_id', 'terms' => $current_term->term_id, ]], ]; $products = (new WP_Query( $args ))->get_posts(); usort($products, 'mce_sort_products_callback'); // شروع خروجی با BOM echo "\xEF\xBB\BF"; // ساخت هدر به صورت دستی $header = [ 'نام محصول', 'وضعیت موجودی', 'قیمت (تومان)' ]; echo mce_generate_csv_row($header); // ساخت ردیفها برای هر محصول if ( ! empty( $products ) ) { foreach ( $products as $post ) { $product = wc_get_product( $post->ID ); $name = $product->get_name(); $stock_status = $product->is_in_stock() ? 'موجود' : 'ناموجود'; $price = $product->get_price(); $price_display = ($price === '' || $price == 0) ? 'بدون قیمت' : number_format($price, 0, '', ''); $row = [ $name, $stock_status, $price_display ]; echo mce_generate_csv_row($row); } } exit(); } /** * تابع جدید برای ساخت دستی یک ردیف CSV * این تابع هر مقدار را داخل دابل کوتیشن قرار میدهد و کاراکترهای فارسی را به درستی مدیریت میکند. */ function mce_generate_csv_row( $data ) { $row = ''; $separator = ''; foreach( $data as $cell ) { // برای جلوگیری از بههم ریختن CSV، هر دابل کوتیشن داخل متن را با دو دابل کوتیشن جایگزین میکنیم $cell = str_replace( '"', '""', $cell ); $row .= $separator . '"' . $cell . '"'; $separator = ','; } $row .= "\r\n"; // اضافه کردن کاراکتر خط جدید // مهم: خروجی نهایی را به صورت اجباری به UTF-8 تبدیل میکنیم return mb_convert_encoding( $row, 'UTF-8' ); } /** * تابع مرتبسازی محصولات (بدون تغییر) */ function mce_sort_products_callback($a, $b) { $product_a = wc_get_product($a->ID); $product_b = wc_get_product($b->ID); $a_in_stock = $product_a->is_in_stock(); $b_in_stock = $product_b->is_in_stock(); $price_a = (float) $product_a->get_price(); $price_b = (float) $product_b->get_price(); if ($a_in_stock && !$b_in_stock) return -1; if (!$a_in_stock && $b_in_stock) return 1; $a_has_price = $price_a > 0; $b_has_price = $price_b > 0; if ($a_has_price && !$b_has_price) return -1; if (!$a_has_price && $b_has_price) return 1; if ($a_has_price && $b_has_price) { if ($price_a !== $price_b) return $price_b <=> $price_a; } return strcmp($product_a->get_name(), $product_b->get_name()); }
نمایش 161–200 از 685 نتیجهSorted by popularity