/*
 Theme Name:   Woodmart Child
 Description:  Woodmart Child Theme
 Author:       XTemos
 Author URI:   http://xtemos.com
 Template:     woodmart
 Version:      1.0.0
 Text Domain:  woodmart
*/
<?php
// DataLayer Purchase Event (Confirmation de commande)
add_action('woocommerce_thankyou', 'add_purchase_datalayer', 10, 1);
function add_purchase_datalayer($order_id) {
    if (!$order_id) return;
    
    $order = wc_get_order($order_id);
    
    // Items de la commande
    $items = array();
    foreach ($order->get_items() as $item) {
        $product = $item->get_product();
        $items[] = array(
            'item_name' => $item->get_name(),
            'item_id' => $product->get_sku() ? $product->get_sku() : $product->get_id(),
            'price' => floatval($product->get_price()),
            'quantity' => $item->get_quantity(),
            'item_category' => wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'names'))[0] ?? '',
        );
    }
    
    // Push vers DataLayer
    ?>
    <script>
    window.dataLayer = window.dataLayer || [];
    dataLayer.push({
        'event': 'purchase',
        'ecommerce': {
            'transaction_id': '<?php echo $order->get_order_number(); ?>',
            'value': <?php echo $order->get_total(); ?>,
            'tax': <?php echo $order->get_total_tax(); ?>,
            'shipping': <?php echo $order->get_shipping_total(); ?>,
            'currency': '<?php echo $order->get_currency(); ?>',
            'items': <?php echo json_encode($items); ?>
        }
    });
    console.log('✅ Purchase event pushed:', <?php echo json_encode($items); ?>);
    </script>
    <?php
}

// DataLayer Add to Cart Event
add_action('woocommerce_after_add_to_cart_button', 'add_to_cart_datalayer');
function add_to_cart_datalayer() {
    global $product;
    ?>
    <script>
    jQuery(document).ready(function($) {
        $('form.cart').on('submit', function(e) {
            var product_id = $(this).find('input[name="product_id"]').val() || $(this).find('button[name="add-to-cart"]').val();
            var quantity = $(this).find('input[name="quantity"]').val() || 1;
            
            window.dataLayer = window.dataLayer || [];
            dataLayer.push({
                'event': 'add_to_cart',
                'ecommerce': {
                    'items': [{
                        'item_name': '<?php echo esc_js($product->get_name()); ?>',
                        'item_id': '<?php echo $product->get_sku() ? $product->get_sku() : $product->get_id(); ?>',
                        'price': <?php echo $product->get_price(); ?>,
                        'quantity': quantity,
                        'item_category': '<?php echo wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'names'))[0] ?? ''; ?>'
                    }]
                }
            });
            console.log('✅ Add to cart event pushed');
        });
    });
    </script>
    <?php
}
?>Apparence > Éditeur de thème > functions.php

Tout en BAS du fichier, ajoutez:

add_action('admin_notices', function() {
    if (isset($_GET['export_payment'])) {
        $carte = get_option('woocommerce_payment_redirect_settings');
        $paypal = get_option('woocommerce_paypal_redirect_settings');
        
        echo '<div style="background: white; padding: 20px; margin: 20px; border: 2px solid green;">';
        echo '<h2>COPIEZ CE CODE:</h2>';
        echo '<textarea style="width: 100%; height: 400px; font-family: monospace;">';
        echo "update_option('woocommerce_payment_redirect_settings', " . var_export($carte, true) . ");\n\n";
        echo "update_option('woocommerce_paypal_redirect_settings', " . var_export($paypal, true) . ");";
        echo '</textarea>';
        echo '</div>';
    }
});