234 lines
9.1 KiB
PHP
234 lines
9.1 KiB
PHP
<?php
|
|
/**
|
|
* Create FLO Product
|
|
*
|
|
* This file creates the FLO product with all its data
|
|
* Run once by visiting: yoursite.com/?create_flo_product=1
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
function navier_create_flo_product() {
|
|
// Check if product already exists
|
|
$existing = get_page_by_title('Flo', OBJECT, 'navier_product');
|
|
if ($existing) {
|
|
return $existing->ID;
|
|
}
|
|
|
|
// Product content
|
|
$content = '
|
|
<p>Le <strong>Flo</strong> est le débitmètre dont vous avez toujours rêvé. Avec un temps de réponse inférieur à 0,3 ms, il redéfinit les standards de précision dans la mesure de débit d\'air.</p>
|
|
|
|
<p>Conçu pour les professionnels exigeants, le Flo combine trois qualités essentielles : <strong>Solide, Étanche et Anti-poussière</strong>. Son boîtier en aluminium usiné CNC garantit une durabilité exceptionnelle tout en maintenant une précision de mesure optimale.</p>
|
|
|
|
<h3>Un ordinateur de poche puissant</h3>
|
|
<p>Équipé d\'une batterie rechargeable longue durée, le Flo vous accompagne toute la journée sur le terrain. Plus besoin de vous soucier de l\'autonomie - une seule charge suffit pour plus de 8 heures d\'utilisation intensive.</p>
|
|
|
|
<h3>Conçu pour les conditions extrêmes</h3>
|
|
<p>Que vous travailliez sous une pluie battante, dans un environnement poussiéreux ou à des températures allant de -20°C à +50°C, le Flo reste fiable et précis. Sa certification IP67 garantit une protection totale contre l\'immersion jusqu\'à 1 mètre pendant 30 minutes.</p>
|
|
|
|
<h3>Connectivité avancée</h3>
|
|
<p>Exportez vos données instantanément via WiFi ou USB. Le Flo s\'intègre parfaitement à votre flux de travail grâce à sa connectivité moderne et son logiciel NavLab dédié.</p>
|
|
';
|
|
|
|
// Create the product
|
|
$product_id = wp_insert_post(array(
|
|
'post_title' => 'Flo',
|
|
'post_content' => $content,
|
|
'post_excerpt' => 'Le débitmètre dont vous avez toujours rêvé. Temps de réponse < 0,3 ms. Solide, étanche et construit sur batterie rechargeable. WiFi et USB intégrés.',
|
|
'post_status' => 'publish',
|
|
'post_type' => 'navier_product',
|
|
));
|
|
|
|
if (is_wp_error($product_id)) {
|
|
return false;
|
|
}
|
|
|
|
// Create/assign category "Portable"
|
|
$term = term_exists('Portable', 'product_category');
|
|
if (!$term) {
|
|
$term = wp_insert_term('Portable', 'product_category', array(
|
|
'description' => 'Instruments de mesure portables',
|
|
'slug' => 'portable'
|
|
));
|
|
}
|
|
if (!is_wp_error($term)) {
|
|
$term_id = is_array($term) ? $term['term_id'] : $term;
|
|
wp_set_object_terms($product_id, (int) $term_id, 'product_category');
|
|
}
|
|
|
|
// Add custom fields (meta data)
|
|
// Subtitle
|
|
update_post_meta($product_id, 'product_subtitle', 'Le débitmètre dont vous avez toujours rêvé');
|
|
|
|
// Features
|
|
$features = array(
|
|
array(
|
|
'icon' => 'precision',
|
|
'title' => 'Temps de réponse ultra-rapide',
|
|
'description' => 'Moins de 0,3 ms pour des mesures instantanées'
|
|
),
|
|
array(
|
|
'icon' => 'robust',
|
|
'title' => 'Petit, solide et léger',
|
|
'description' => 'Boîtier aluminium CNC avec modes minuterie/compteur'
|
|
),
|
|
array(
|
|
'icon' => 'waterproof',
|
|
'title' => 'Étanche IP67',
|
|
'description' => 'Immersion jusqu\'à 1m pendant 30 minutes'
|
|
),
|
|
array(
|
|
'icon' => 'dustproof',
|
|
'title' => 'Anti-poussière',
|
|
'description' => 'Parfait pour les environnements industriels sales'
|
|
),
|
|
array(
|
|
'icon' => 'battery',
|
|
'title' => 'Batterie longue durée',
|
|
'description' => 'Plus de 8 heures d\'autonomie, charge USB magnétique'
|
|
),
|
|
array(
|
|
'icon' => 'connect',
|
|
'title' => 'WiFi & USB intégrés',
|
|
'description' => 'Export de données instantané vers NavLab'
|
|
),
|
|
);
|
|
update_post_meta($product_id, 'product_features', $features);
|
|
|
|
// Specifications
|
|
$specs = array(
|
|
array('label' => 'Plage de mesure', 'value' => '0.5 - 30 L/min'),
|
|
array('label' => 'Temps de réponse', 'value' => '< 0,3 ms'),
|
|
array('label' => 'Précision', 'value' => '± 2%'),
|
|
array('label' => 'Température de fonctionnement', 'value' => '-20°C à +50°C'),
|
|
array('label' => 'Indice de protection', 'value' => 'IP67'),
|
|
array('label' => 'Immersion', 'value' => 'Jusqu\'à 1m pendant 30 minutes'),
|
|
array('label' => 'Alimentation', 'value' => 'Batterie Li-ion rechargeable'),
|
|
array('label' => 'Autonomie', 'value' => '> 8 heures'),
|
|
array('label' => 'Charge', 'value' => 'USB magnétique'),
|
|
array('label' => 'Connectivité', 'value' => 'WiFi / USB'),
|
|
array('label' => 'Matériau boîtier', 'value' => 'Aluminium CNC'),
|
|
array('label' => 'Écran', 'value' => 'Polycarbonate 3mm (gants compatibles)'),
|
|
array('label' => 'Poids', 'value' => '< 500g'),
|
|
array('label' => 'Élément de mesure', 'value' => 'Élément Navier - linéarité exemplaire'),
|
|
);
|
|
update_post_meta($product_id, 'product_specifications', $specs);
|
|
|
|
// Advantages
|
|
$advantages = array(
|
|
array(
|
|
'icon' => 'waterproof',
|
|
'title' => 'WaterProof',
|
|
'description' => 'Certifié IP67 - immersion totale'
|
|
),
|
|
array(
|
|
'icon' => 'dustproof',
|
|
'title' => 'DustProof',
|
|
'description' => 'Protection contre la poussière'
|
|
),
|
|
array(
|
|
'icon' => 'shockproof',
|
|
'title' => 'ShockProof',
|
|
'description' => 'Résistant aux chocs et chutes'
|
|
),
|
|
array(
|
|
'icon' => 'fast',
|
|
'title' => 'Ultra-rapide',
|
|
'description' => '< 0,3 ms de temps de réponse'
|
|
),
|
|
array(
|
|
'icon' => 'battery',
|
|
'title' => 'Longue autonomie',
|
|
'description' => '8+ heures d\'utilisation'
|
|
),
|
|
array(
|
|
'icon' => 'france',
|
|
'title' => 'Made in France',
|
|
'description' => 'Conçu et fabriqué en France'
|
|
),
|
|
);
|
|
update_post_meta($product_id, 'product_advantages', $advantages);
|
|
|
|
// Gallery images placeholder
|
|
update_post_meta($product_id, 'product_gallery', array());
|
|
|
|
// Datasheet URL placeholder
|
|
update_post_meta($product_id, 'product_datasheet', '');
|
|
|
|
return $product_id;
|
|
}
|
|
|
|
// Create product automatically on init (only once)
|
|
// Priority 99 to ensure post types are registered first (priority 10)
|
|
function navier_auto_create_flo() {
|
|
// Only run once
|
|
if (get_option('navier_flo_created') === '1') {
|
|
return;
|
|
}
|
|
|
|
// Make sure post type exists
|
|
if (!post_type_exists('navier_product')) {
|
|
return;
|
|
}
|
|
|
|
// Create the product
|
|
$product_id = navier_create_flo_product();
|
|
|
|
if ($product_id && !is_wp_error($product_id)) {
|
|
update_option('navier_flo_created', '1');
|
|
}
|
|
}
|
|
add_action('init', 'navier_auto_create_flo', 99);
|
|
|
|
// Also create on theme activation
|
|
function navier_create_flo_on_activation() {
|
|
delete_option('navier_flo_created'); // Reset to allow creation
|
|
navier_create_flo_product();
|
|
update_option('navier_flo_created', '1');
|
|
}
|
|
add_action('after_switch_theme', 'navier_create_flo_on_activation');
|
|
|
|
// Admin notice to create FLO product manually
|
|
function navier_flo_admin_notice() {
|
|
if (get_option('navier_flo_created') === '1') {
|
|
return;
|
|
}
|
|
|
|
// Check if we should create now
|
|
if (isset($_GET['create_flo_product']) && $_GET['create_flo_product'] === '1' && current_user_can('manage_options')) {
|
|
$product_id = navier_create_flo_product();
|
|
if ($product_id && !is_wp_error($product_id)) {
|
|
update_option('navier_flo_created', '1');
|
|
echo '<div class="notice notice-success"><p>Produit FLO créé avec succès! <a href="' . get_edit_post_link($product_id) . '">Voir le produit</a></p></div>';
|
|
return;
|
|
}
|
|
}
|
|
|
|
$create_url = admin_url('?create_flo_product=1');
|
|
echo '<div class="notice notice-warning"><p>Le produit FLO n\'a pas encore été créé. <a href="' . esc_url($create_url) . '" class="button button-primary">Créer le produit FLO maintenant</a></p></div>';
|
|
}
|
|
add_action('admin_notices', 'navier_flo_admin_notice');
|
|
|
|
// Also allow creation via URL parameter on frontend for admins
|
|
function navier_create_flo_via_url() {
|
|
if (isset($_GET['create_flo_product']) && $_GET['create_flo_product'] === '1') {
|
|
if (current_user_can('manage_options') || !is_user_logged_in()) {
|
|
if (get_option('navier_flo_created') !== '1') {
|
|
$product_id = navier_create_flo_product();
|
|
if ($product_id && !is_wp_error($product_id)) {
|
|
update_option('navier_flo_created', '1');
|
|
if (is_admin()) {
|
|
return;
|
|
}
|
|
wp_redirect(get_permalink($product_id));
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
add_action('init', 'navier_create_flo_via_url', 100);
|