Maybe you have the bad hook. look at this exemple : i had the same error before
Allowed memory size of 1317011456 bytes exhausted (tried to allocate 262144 bytes) in /home/mala4322/antivirusedition.nash-project.name/wp-content/plugins/woocommerce/includes/class-wc-cart.php on line 623
I changet add_action( 'woocommerce_cart_updated', [$this, 'sauver_champs_perso_panier'] ); for add_action( 'woocommerce_update_cart_action_cart_updated', [$this, 'sauver_champs_perso_panier'] );
and it was solved
public function __construct() {
// Lors du UPDATE CART → on ajoute les données
add_action( 'woocommerce_update_cart_action_cart_updated', [$this, 'sauver_champs_perso_panier'] );
// Réafficher dans le panier
add_filter( 'woocommerce_get_item_data', [$this, 'afficher_donnees_panier'], 10, 2 );
// Sauvegarde dans la commande lors du checkout
// add_action( 'woocommerce_checkout_create_order_line_item', [$this, 'sauver_donnees_dans_commande'], 10, 4 );
// add_action( 'woocommerce_update_cart_action_cart_updated', [$this, 'save_custom_cart_item_data']);
}
/**
* Sauvegarde des champs quand l'utilisateur clique "Update Cart"
*/
function sauver_champs_perso_panier() {
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Durée perso
if ( isset($_POST['alm_duree'][$cart_item_key]) ) {
$duree = sanitize_text_field( $_POST['alm_duree'][$cart_item_key] );
WC()->cart->cart_contents[$cart_item_key]['alm_duree'] = $duree;
}
// Client perso
if ( isset($_POST['alm_client'][$cart_item_key]) ) {
$client_id = intval($_POST['alm_client'][$cart_item_key]);
WC()->cart->cart_contents[$cart_item_key]['alm_client'] = $client_id;
}
}
WC()->cart->set_session();
}
ini_set('memory_limit', '2048M');Or better to find out the reason why its taking so much memory.