Cart

Votre panier est actuellement vide.

Retour à la boutique

Engage Your Visitors!

Click here to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis pulvinar dapibus.

Engage Your Visitors!

Click here to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis pulvinar dapibus.

Tarifs livraison!

Merci d’utiliser la saisie intuitive pour renseigner la ville, cela permet de calculer le tarif de livraison.

🔔 Veuillez saisir le nom de votre ville en lettres latines pour un calcul précis des frais (20–45 DH).
Pas d’inquiétude : toute erreur sera corrigée lors de la validation de votre commande.

// === Meta CAPI en USD (WooCommerce -> Meta) =============================== // 1) Champs rapides dans Réglages > Général add_action('admin_init', function () { // Taux MAD -> USD (1 MAD * taux = USD) register_setting('general', 'mad_to_usd_rate', ['type' => 'number', 'sanitize_callback' => function($v){ return is_numeric($v) ? (float)$v : 0.0; }, 'default' => 0.10]); add_settings_field('mad_to_usd_rate', 'Taux MAD → USD', function () { $v = get_option('mad_to_usd_rate', 0.10); echo ' Ex. 0.10 = 1 MAD vaut 0,10 USD'; }, 'general'); // Pixel ID register_setting('general', 'meta_pixel_id', ['type' => 'string', 'sanitize_callback' => 'sanitize_text_field']); add_settings_field('meta_pixel_id', 'Meta Pixel ID', function () { $v = get_option('meta_pixel_id', ''); echo ''; }, 'general'); // Access Token register_setting('general', 'meta_capi_token', ['type' => 'string', 'sanitize_callback' => 'sanitize_text_field']); add_settings_field('meta_capi_token', 'Meta CAPI Access Token', function () { $v = get_option('meta_capi_token', ''); echo ''; }, 'general'); }); // 2) Envoi automatique après paiement (page Merci) add_action('woocommerce_thankyou', function($order_id){ if (!$order_id) return; $order = wc_get_order($order_id); if (!$order) return; // Récup options $pixel_id = trim((string) get_option('meta_pixel_id', '')); $access_token = trim((string) get_option('meta_capi_token', '')); $rate = (float) get_option('mad_to_usd_rate', 0.10); if (empty($pixel_id) || empty($access_token) || $rate <= 0) { // Incomplet : rien n'est envoyé return; } // Totaux $total_mad = (float) $order->get_total(); $total_usd = round($total_mad * $rate, 2); // ID d’événement stable (utile pour dédup Pixel + CAPI) $event_id = 'wc_order_' . $order->get_id(); // User data (recommandé, hachés pour correspondance) $em = $order->get_billing_email(); $hashed_email = $em ? hash('sha256', strtolower(trim($em))) : null; // IP & UA (si disponibles) $client_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; $client_ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; // Détails produits (optionnel mais utile dans Events Manager) $contents = []; foreach ($order->get_items() as $item) { $product = $item->get_product(); if (!$product) continue; $pid = $product->get_parent_id() ?: $product->get_id(); // tu forces déjà l’ID simple ailleurs $contents[] = [ 'id' => (string) $pid, 'quantity' => (int) $item->get_quantity(), 'item_price' => (float) wc_get_price_excluding_tax($product) ]; } $payload = [ 'data' => [[ 'event_name' => 'Purchase', 'event_time' => time(), 'action_source' => 'website', 'event_source_url' => home_url('/'), 'event_id' => $event_id, 'user_data' => array_filter([ 'em' => $hashed_email, 'client_ip_address' => $client_ip, 'client_user_agent' => $client_ua, ]), 'custom_data' => array_filter([ 'currency' => 'USD', 'value' => $total_usd, 'contents' => $contents ?: null, 'content_type' => $contents ? 'product' : null, // Si tu veux passer le shipping/taxes en clair : // 'shipping' => (float) $order->get_shipping_total(), // 'tax' => (float) $order->get_total_tax(), ]), ]] ]; // Envoi à Meta Graph API $url = sprintf('https://graph.facebook.com/v20.0/%s/events?access_token=%s', rawurlencode($pixel_id), rawurlencode($access_token)); $response = wp_remote_post($url, [ 'headers' => ['Content-Type' => 'application/json'], 'body' => wp_json_encode($payload), 'timeout' => 15, ]); // (facultatif) log si erreur if (is_wp_error($response) || wp_remote_retrieve_response_code($response) >= 300) { error_log('[META CAPI USD] Echec envoi pour commande '.$order_id.' : '.print_r($response, true)); } }, 30);
Retour en haut
Review Your Cart
0
Add Coupon Code
Subtotal