} echo "\n\n"; } } add_action( 'wp_print_styles', 'ttc27_debug_enqueued_styles', 99 ); // 7. Preserve TTC's price policy: zero-price products = "LIÊN HỆ"; // free-on-sale products show original price struck out, then "Free!". if ( ! function_exists( 'ttc27_wc_custom_get_price_html' ) ) { function ttc27_wc_custom_get_price_html( $price_html, $product ) { if ( ! ( $product instanceof WC_Product ) ) { return $price_html; } $value = $product->get_price(); // Never convert unset/non-numeric prices to zero. if ( ! is_numeric( $value ) || (float) $value !== 0.0 ) { return $price_html; } $regular = $product->get_regular_price(); if ( $product->is_on_sale() && is_numeric( $regular ) && (float) $regular > 0 ) { $display_regular = wc_get_price_to_display( $product, array( 'price' => $regular ) ); return wc_format_sale_price( $display_regular, esc_html__( 'Free!', 'woocommerce' ) ); } return '' . esc_html( 'LIÊN HỆ' ) . ''; } } add_filter( 'woocommerce_get_price_html', 'ttc27_wc_custom_get_price_html', 10, 2 ); // 8. Preserve custom VND currency symbol. if ( ! function_exists( 'ttc27_change_currency_symbol' ) ) { function ttc27_change_currency_symbol( $currency_symbol, $currency ) { return 'VND' === $currency ? 'VNĐ' : $currency_symbol; } } add_filter( 'woocommerce_currency_symbol', 'ttc27_change_currency_symbol', 10, 2 ); // 9. Preserve existing GA4 ID. DISABLE if Site Kit/Rank Math/GTM already embeds this ID. if ( ! defined( 'TTC27_ENABLE_GA4' ) ) { define( 'TTC27_ENABLE_GA4', true ); } if ( ! function_exists( 'ttc27_load_ga4' ) ) { function ttc27_load_ga4() { if ( is_admin() || ! TTC27_ENABLE_GA4 ) { return; } wp_enqueue_script( 'ttc27-ga4', 'https://www.googletagmanager.com/gtag/js?id=G-STVLX9CRK1', array(), null, array( 'in_footer' => false, 'strategy' => 'async' ) ); wp_add_inline_script( 'ttc27-ga4', 'window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag("js", new Date()); gtag("config", "G-STVLX9CRK1");', 'after' ); } } add_action( 'wp_enqueue_scripts', 'ttc27_load_ga4', 30 ); // 10. Retain "ĐẶT HÀNG NGAY" for purchasable, in-stock products; // preserve "Select options"/"Read more" on archives for variable/grouped/out-of-stock items. if ( ! function_exists( 'ttc27_single_add_to_cart_text' ) ) { function ttc27_single_add_to_cart_text( $text ) { global $product; if ( $product instanceof WC_Product && $product->is_purchasable() && $product->is_in_stock() ) { return 'ĐẶT HÀNG NGAY'; } return $text; } } add_filter( 'woocommerce_product_single_add_to_cart_text', 'ttc27_single_add_to_cart_text', 10, 1 ); if ( ! function_exists( 'ttc27_archive_add_to_cart_text' ) ) { function ttc27_archive_add_to_cart_text( $text, $product ) { if ( $product instanceof WC_Product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() ) { return 'ĐẶT HÀNG NGAY'; } return $text; } } add_filter( 'woocommerce_product_add_to_cart_text', 'ttc27_archive_add_to_cart_text', 10, 2 ); // 11. Product review shortcode. comments_template() works with CURRENT single-product query only. // Never pretend that id="OTHER_ID" will load another product's reviews. if ( ! function_exists( 'ttc27_product_reviews_shortcode' ) ) { function ttc27_product_reviews_shortcode( $atts ) { if ( ! function_exists( 'wc_get_product' ) || ! function_exists( 'is_product' ) || ! is_product() ) { return ''; } $current_id = (int) get_queried_object_id(); $atts = shortcode_atts( array( 'id' => $current_id ), $atts, 'product_reviews' ); $chosen_id = absint( $atts['id'] ); if ( ! $current_id || $chosen_id !== $current_id || ! wc_get_product( $current_id ) ) { return ''; } ob_start(); comments_template(); return ob_get_clean(); } } add_shortcode( 'product_reviews', 'ttc27_product_reviews_shortcode' ); // 12. Keep existing Woo product-tab behavior. if ( ! function_exists( 'ttc27_remove_reviews_tab' ) ) { function ttc27_remove_reviews_tab( $tabs ) { unset( $tabs['reviews'] ); return $tabs; } } add_filter( 'woocommerce_product_tabs', 'ttc27_remove_reviews_tab', 98 ); if ( ! function_exists( 'ttc27_change_description_tab_title' ) ) { function ttc27_change_description_tab_title( $tabs ) { if ( isset( $tabs['description']['title'] ) ) { $tabs['description']['title'] = 'MÔ TẢ CHI TIẾT SẢN PHẨM'; } return $tabs; } } add_filter( 'woocommerce_product_tabs', 'ttc27_change_description_tab_title', 98 );