is_type( 'variable' ) ) { $prices = $product->get_variation_prices( true ); $min_price = current( $prices['price'] ); if ( 0 == $min_price ) { $max_price = end( $prices['price'] ); $min_reg_price = current( $prices['regular_price'] ); $max_reg_price = end( $prices['regular_price'] ); if ( $min_price !== $max_price ) { $price = wc_format_price_range( $cfp_html, $max_price ); $price .= $product->get_price_suffix(); } elseif ( $product->is_on_sale() && $min_reg_price === $max_reg_price ) { $price = wc_format_sale_price( wc_price( $max_reg_price ), $cfp_html ); $price .= $product->get_price_suffix(); } else { $price = $cfp_html; } } } elseif ( '' === $product->get_price() || 0 == $product->get_price() ) { $price = '' . $cfp_html . ''; } return $price; } // Frontend Hooks $custom_fields_json = aio_get_option('optWcCheckoutFields'); $has_custom_fields = !empty($custom_fields_json) && $custom_fields_json !== '[]'; if ($has_custom_fields) { add_filter( 'woocommerce_checkout_fields', 'aio_tools_CustomDisplayWooCheckoutFields', 99999); // Hide "Additional Information" heading if order_comments is disabled add_filter( 'woocommerce_enable_order_notes_field', 'aio_tools_disable_order_notes_heading', 9999); function aio_tools_disable_order_notes_heading($enable) { $custom_fields_json = aio_get_option('optWcCheckoutFields'); if (!empty($custom_fields_json)) { $custom_fields = json_decode($custom_fields_json, true); if (is_array($custom_fields)) { foreach ($custom_fields as $cf) { if (isset($cf['id']) && $cf['id'] === 'order_comments') { if (!isset($cf['visible']) || !$cf['visible']) { return false; } } } } } return $enable; } } if (aio_get_option('optWcMergeNames') == 1) { add_filter('woocommerce_checkout_fields', 'aio_tools_merge_first_last_name', 100000); } function aio_tools_merge_first_last_name($fields) { if (isset($fields['billing']['billing_first_name'])) { $fields['billing']['billing_first_name']['label'] = __('Họ và Tên', 'aio-tools'); $fields['billing']['billing_first_name']['placeholder'] = __('Nhập đầy đủ Họ và Tên của bạn', 'aio-tools'); $fields['billing']['billing_first_name']['class'] = array('form-row-wide'); } if (isset($fields['billing']['billing_last_name'])) { unset($fields['billing']['billing_last_name']); } if (isset($fields['shipping']['shipping_first_name'])) { $fields['shipping']['shipping_first_name']['label'] = __('Họ và Tên', 'aio-tools'); $fields['shipping']['shipping_first_name']['placeholder'] = __('Nhập đầy đủ Họ và Tên của bạn', 'aio-tools'); $fields['shipping']['shipping_first_name']['class'] = array('form-row-wide'); } if (isset($fields['shipping']['shipping_last_name'])) { unset($fields['shipping']['shipping_last_name']); } return $fields; } // Direct Checkout Modes if (!empty(aio_get_option('opt-woo-direct-checkout')) || !empty(aio_get_option('opt-direct-checkout'))) { $direct_checkout_mode = aio_get_option('optDirectCheckoutMode', ''); if (empty($direct_checkout_mode)) { $direct_checkout_mode = 'redirect'; // Legacy fallback } if ($direct_checkout_mode === 'redirect') { add_filter('woocommerce_add_to_cart_redirect', 'aio_tools_direct_checkout_redirect'); } elseif ($direct_checkout_mode === 'lightbox') { add_action('wp_footer', 'aio_tools_render_quick_buy_lightbox'); } } function aio_tools_render_quick_buy_lightbox() { if ( ! function_exists( 'is_woocommerce' ) ) return; ?>
' . esc_html($cf['label']) . ': ' . esc_html($value) . '
'; } } } } add_action('woocommerce_checkout_create_order', 'aio_tools_save_custom_checkout_fields_to_order', 10, 2); function aio_tools_save_custom_checkout_fields_to_order( $order, $data ) { $custom_fields_json = aio_get_option('optWcCheckoutFields'); if (empty($custom_fields_json)) return; $custom_fields = json_decode($custom_fields_json, true); if (!is_array($custom_fields)) return; foreach ($custom_fields as $cf) { $id = isset($cf['id']) ? $cf['id'] : ''; $is_custom = isset($cf['is_custom']) ? $cf['is_custom'] : false; if ($is_custom && !empty($id) && isset($_POST[$id])) { $order->update_meta_data( '_' . $id, sanitize_text_field($_POST[$id]) ); } } } /* ========================================================================== WCP-1. ASSET UNLOADER ========================================================================== */ if ( !empty(aio_get_option('optEnableWcUnloader')) ) { add_action('wp_enqueue_scripts', 'aio_tools_wc_asset_unloader', 99); } function aio_tools_wc_asset_unloader() { if (function_exists('is_woocommerce')) { if (!is_woocommerce() && !is_cart() && !is_checkout() && !is_account_page()) { wp_dequeue_style('woocommerce-layout'); wp_dequeue_style('woocommerce-smallscreen'); wp_dequeue_style('woocommerce-general'); wp_dequeue_style('wc-blocks-vendors-style'); wp_dequeue_style('wc-blocks-style'); wp_dequeue_script('wc-add-to-cart'); wp_dequeue_script('woocommerce'); wp_dequeue_script('wc-cart-fragments'); } } } /* ========================================================================== WCP-2. FAKE SALES POPUP ========================================================================== */ if ( !empty(aio_get_option('optEnableWcFakeSales')) ) { add_action('wp_footer', 'aio_tools_render_fake_sales_popup'); } function aio_tools_render_fake_sales_popup() { if (!function_exists('wc_get_products')) return; $sales_data = get_transient('aio_fake_sales_products'); if ( false === $sales_data ) { $products = wc_get_products([ 'status' => 'publish', 'limit' => 50, 'orderby' => 'date', 'order' => 'DESC' ]); if (empty($products)) return; $sales_data = []; $names = ['Nguyễn Văn Tuấn', 'Trần Thị Thủy Tiên', 'Lê Hoàng Hải Đăng', 'Phạm Minh Duy', 'Hoàng Thanh Tùng']; $cities = ['Hà Nội', 'TP.HCM', 'Đà Nẵng', 'Hải Phòng', 'Cần Thơ', 'Bình Dương', 'Đồng Nai']; foreach ($products as $product) { $sales_data[] = [ 'name' => $names[array_rand($names)], 'city' => $cities[array_rand($cities)], 'product' => $product->get_name(), 'url' => $product->get_permalink(), 'image' => wp_get_attachment_image_url($product->get_image_id(), 'thumbnail'), 'time' => wp_rand(1, 59) . ' phút trước' ]; } set_transient('aio_fake_sales_products', $sales_data, 2 * HOUR_IN_SECONDS); } if (count($sales_data) > 10) { $random_keys = array_rand($sales_data, 10); $filtered_data = array_intersect_key($sales_data, array_flip($random_keys)); $sales_data = array_values($filtered_data); } ?> cart && WC()->cart->is_empty() ) { wp_safe_redirect( wc_get_page_permalink( 'shop' ) ); exit; } } /* ========================================================================== WCP-5. TRUST BADGES ========================================================================== */ if ( !empty(aio_get_option('optWcTrustBadges')) ) { add_action('woocommerce_after_add_to_cart_button', 'aio_tools_render_trust_badges'); } function aio_tools_render_trust_badges() { ?>