/** * HYBSTER FICHE TECHNIQUE V2 * Adapté aux vrais noms de champs ACF détectés via [hybster_debug_fields] * Champs présents : tensile_modulus_mpa, tensile_strength_mpa, tensile_elongation_pct, * charpy_notched_iso179_kj_m2, flexural_modulus_mpa, density_g_cm3, * matiere_famille_brut, applications_recommandees, renforce */ add_shortcode('hybster_fiche_technique', function() { if (get_post_type() !== 'matiere') return ''; $pid = get_the_ID(); // ── Lecture des champs PRÉSENTS dans ACF ───────────────────────────────────── $famille = get_field('matiere_famille_brut', $pid) ?: '—'; $renforce = get_field('renforce', $pid) ?: '—'; $filler = get_field('filler_reinforcement_raw', $pid) ?: '—'; $density = get_field('density_g_cm3', $pid) ?: 'N/A'; $tensile_mod = get_field('tensile_modulus_mpa', $pid) ?: 'N/A'; $tensile_str = get_field('tensile_strength_mpa', $pid) ?: 'N/A'; $tensile_elong = get_field('tensile_elongation_pct', $pid) ?: 'N/A'; $charpy = get_field('charpy_notched_iso179_kj_m2', $pid) ?: 'N/A'; $flex_mod = get_field('flexural_modulus_mpa', $pid) ?: 'N/A'; $flex_str = get_field('flexural_strength_mpa', $pid) ?: 'N/A'; $shore_a = get_field('durometer_shore_a', $pid) ?: '—'; $shore_d = get_field('durometer_shore_d', $pid) ?: '—'; $applications = get_field('applications_recommandees', $pid) ?: 'Consulter notre BE.'; $features = get_field('features', $pid) ?: '—'; $uses = get_field('uses', $pid) ?: '—'; // ── Lecture des champs À CRÉER (retour vide si absents) ────────────────────── $nom_commercial = get_field('nom_commercial', $pid) ?: get_the_title(); $sigle = get_field('sigle', $pid) ?: $famille; $process = get_field('process_compatibles', $pid) ?: '—'; $normes = get_field('normes_certifications', $pid) ?: '—'; $tg = get_field('tg', $pid); $hdt = get_field('hdt', $pid); $temp_min = get_field('temp_usage_min', $pid); $temp_max = get_field('temp_usage_max', $pid); $meca_note = get_field('mecanique_note', $pid) ?: 0; $therm_note = get_field('thermique_note', $pid) ?: 0; $chim_note = get_field('chimique_note', $pid) ?: 0; $uv_note = get_field('uv_note', $pid) ?: 0; $ul94 = get_field('ul94', $pid) ?: '—'; // ── Fonction helper : barre de score (note /5) ─────────────────────────────── $bar = function($note, $max = 5, $color = '#0055b1') { if (!$note) return 'Non renseigné'; $pct = ($note / $max) * 100; return '' . $note . '/' . $max . '
'; }; // ── Fonction helper : nettoyer les longues chaînes ACF ──────────────────────── // Les valeurs comme "1700 to 2830 (ASTM D638); 1730 to 2870 (ISO 527-1)" // → on affiche la première plage seulement en version courte $short = function($raw, $suffix = '') { if ($raw === 'N/A' || $raw === '—') return $raw; // Prendre uniquement la partie avant le premier " (" ou ";" $clean = preg_split('/\s*[\(;]/', $raw)[0]; return trim($clean) . ($suffix ? ' ' . $suffix : ''); }; // ── Construction HTML ───────────────────────────────────────────────────────── $h = '| Nom Commercial | ' . esc_html($nom_commercial) . ' |
|---|---|
| Famille | ' . esc_html($famille) . ' |
| Densité | ' . esc_html($short($density, 'g/cm³')) . ' |
| Renfort / Charge | ' . esc_html($filler !== '—' ? $filler : $renforce) . ' |
| Process | ' . esc_html($process) . ' |
| Normes / UL94 | ' . esc_html($normes !== '—' ? $normes : $ul94) . ' |
| Module traction | ' . esc_html($short($tensile_mod, 'MPa')) . ' |
|---|---|
| Résistance traction | ' . esc_html($short($tensile_str, 'MPa')) . ' |
| Allongement rupture | ' . esc_html($short($tensile_elong, '%')) . ' |
| Module flexion | ' . esc_html($short($flex_mod, 'MPa')) . ' |
| Résistance flexion | ' . esc_html($short($flex_str, 'MPa')) . ' |
| Choc Charpy entaillé | ' . esc_html($short($charpy, 'kJ/m²')) . ' |
| Dureté Shore A / D | ' . ($shore_a !== '—' ? 'A: '.esc_html($shore_a) : '') . ($shore_d !== '—' ? ' D: '.esc_html($shore_d) : '—') . ' |
| Score global | ' . $bar($meca_note) . ' |
| Tg | ' . ($tg ? esc_html($tg).' °C' : 'Champ à créer') . ' |
|---|---|
| HDT (0.45 MPa) | ' . ($hdt ? esc_html($hdt).' °C' : 'Champ à créer') . ' |
| T° usage | ' . ($temp_min && $temp_max ? esc_html($temp_min).' à '.esc_html($temp_max).' °C' : 'Champs à créer') . ' |
| Score thermique | ' . $bar($therm_note, 5, '#dc3545') . ' |
| Score chimique | ' . $bar($chim_note, 5, '#28a745') . ' |
|---|---|
| Score UV | ' . $bar($uv_note, 5, '#fd7e14') . ' |
ℹ️ Renseignez les champs chimique_note et uv_note dans ACF pour activer ces barres.
' . nl2br(esc_html($applications)) . '
' . esc_html($applications) . '
' . ($features !== '—' ? esc_html($features) : 'Consulter notre bureau d\'études.') . '
* Données indicatives issues de bases normalisées (ASTM/ISO). Plages typiques pour un grade standard non renforcé.
'; $h .= '