Hướng dẫn hiển thị thông tin tùy chỉnh và giảm giá theo loại hiển thị trong WooCommerce

/**
 * Display custom promotion information and discount on WooCommerce product page.
 */
function display_custom_promotion_info() {
    global $post;

    // Get custom field values
    $promotion_info = get_field('promotion_info', 'option');
    $display_type = get_field('display_type', 'option');
    $product_list = get_field('product_list', 'option');
    $discount_info = get_field('discount_info', 'option');

    // Check if the product list exists
    if ($product_list) {
        $product_ids = array_map(function($product) {
            return $product->ID;
        }, $product_list);

        // Display promotion information based on the display type
        if (($display_type === 'lt' && !is_single($product_ids)) ||
            ($display_type === 'dc' && is_single($product_ids)) ||
            $display_type === 'tc') {
            echo '<div class="promotion-info">' . esc_html($promotion_info) . '</div>';
        }
    }

    // Display discount information if available
    if (!empty($discount_info)) {
        echo '<div class="discount-info">' . esc_html($discount_info) . '</div>';
    }
}

// Add function to WooCommerce single product summary hook
add_action('woocommerce_single_product_summary', 'display_custom_promotion_info', 20);