// Schema add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) { global $product; if ( ! $product || ! $product->is_type( 'simple' ) ) { return $entity; } $entity['brand'] = "GullPrint"; $entity['offers'] = [ "@type" => "Offer", "sku" => $product->get_sku(), "price" => $product->get_regular_price(), "priceValidUntil" => "2025-12-31", "availability" => "http://schema.org/InStock", "url" => $product->get_permalink(), "priceCurrency" => get_woocommerce_currency(), "shippingDetails" => [ "@type" => "OfferShippingDetails", "shippingRate" => [ "@type" => "MonetaryAmount", "value" => 5.99, "currency" => "USD" ], "shippingDestination" => [ "@type" => "DefinedRegion", "addressCountry" => "US" ], "deliveryTime" => [ "@type" => "ShippingDeliveryTime", "handlingTime" => [ "unitCode" => "d", "@type" => "QuantitativeValue", "minValue" => 2, "maxValue" => 4 ], "transitTime" => [ "unitCode" => "d", "@type" => "QuantitativeValue", "minValue" => 3, "maxValue" => 7 ] ] ], "hasMerchantReturnPolicy" => [ "@type" => "MerchantReturnPolicy", "value" => true, "returnPolicyCategory" => "https://schema.org/MerchantReturnNotPermitted", "applicableCountry" => "US" ] ]; return $entity; }); function track_bing_conversion() { if ( is_order_received_page() ) { global $wp; $order_id = absint( $wp->query_vars['order-received'] ); $order = wc_get_order( $order_id ); if ( $order ) { $order_total = $order->get_total(); // Lấy giá trị tổng của đơn hàng // Đoạn mã script theo dõi Bing Ads echo " "; } } } add_action( 'wp_footer', 'track_bing_conversion' ); function enqueue_tippy_js() { // Tải thư viện Tippy.js wp_enqueue_script('tippy-js', 'https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js', array(), null, true); wp_enqueue_script('tippy-js-main', 'https://unpkg.com/tippy.js@6/dist/tippy-bundle.umd.min.js', array('tippy-js'), null, true); // Tải CSS của Tippy.js (tùy chọn) wp_enqueue_style('tippy-css', 'https://unpkg.com/tippy.js@6/animations/scale.css'); // Thêm đoạn JavaScript trực tiếp $custom_js = " document.addEventListener('DOMContentLoaded', function() { tippy('[data-tippy-content]', { theme: 'light', // Bạn có thể chỉnh sửa theme ở đây animation: 'scale', // Chỉnh hiệu ứng arrow: true, // Hiển thị mũi tên của tooltip }); }); "; wp_add_inline_script('tippy-js-main', $custom_js); } add_action('wp_enqueue_scripts', 'enqueue_tippy_js'); /** * Chặn public REST API – chỉ cho phép người đã đăng nhập */ add_filter( 'rest_authentication_errors', function( $result ) { // Nếu đã có lỗi trước đó (ví dụ do plugin khác), giữ nguyên if ( true === $result || is_wp_error( $result ) ) { return $result; } // Nếu chưa đăng nhập (nobody), trả về lỗi 401 if ( ! is_user_logged_in() ) { return new WP_Error( 'rest_forbidden', __( 'Bạn cần đăng nhập để truy cập REST API.' ), array( 'status' => 401 ) ); } return $result; }); /** * Hiển thị "In stock" cho sản phẩm KHÔNG bật quản lý tồn kho (Manage stock). * ------------------------------------------------------------- * – Chỉ can thiệp khi: * + Manage stock đang tắt ( $product->managing_stock() === false ) * + Sản phẩm còn hàng ( $product->is_in_stock() === true ) * – Giữ nguyên logic mặc định cho mọi tình huống khác * ------------------------------------------------------------- */ add_filter( 'woocommerce_get_stock_html', 'rockatee_show_instock_no_stock_management', 10, 2 ); function rockatee_show_instock_no_stock_management( $stock_html, $product ) { // Nếu KHÔNG bật Manage stock nhưng sản phẩm còn hàng ⇒ ép hiển thị “In stock” if ( ! $product->managing_stock() && $product->is_in_stock() ) { // Bạn có thể đổi cụm từ này thành “Còn hàng”, “Instock” … tùy ý $stock_html = '

' . esc_html__( 'In stock', 'woocommerce' ) . '

'; } return $stock_html; }