Passare una variabile all’interno di un hook ad un altro hook
-
Buongiorno sono un Jr.Fullstack sulla carta, ma mi reputo più un Front Developer.
Ho bisogno di una mano per quanto riguarda il passaggio di una variabile perchè dovrei stampare subito dopo il nome del prodotto, una volta aggiunto al carello, il path che ho generato.Questo è il codice:
add_action('frm_after_create_entry', 'after_entry_created', 30, 2); function after_entry_created($entry_id, $form_id) { // GLOBALI NELLA FUNZIONE $width = 378; $height = 780; $date = new DateTime(); $idata = explode(" ", $date->format('Y-m-d H:i:s')); // DUBL if($form_id == 11) { $text = ""; $args = array(); $image = array(); if(isset($_POST['item_meta'][59])) { $args['data1'] = $_POST['item_meta'][59]; } if(isset($_POST['item_meta'][219])) { $args['data2'] = $_POST['item_meta'][219]; $text = $args['data2']; } if(isset($_POST['item_meta'][67])) { $args['data3'] = $_POST['item_meta'][67]; $iniziali = $args['data3']; } // Creazione immagine $immagine = imagecreatetruecolor($width, $height); imagefill($immagine, 0, 0, imagecolorallocate($immagine, 255, 255, 255)); //Setto il colore del testo $color = imagecolorallocate($immagine, 0,0,0); if ($iniziali) : $font = "wp-content/themes/barberry-child/assets/fonts/optimaltstd.ttf"; $font_load = imageloadfont("wp-content/themes/barberry-child/assets/fonts/optimaltstd.ttf"); $font_size = 40; $dimension = 50; $h= $height - 140; $width1 = $font_size * strlen($iniziali); $w=($width/2)-($width1/2); imagettftext($immagine, $dimension, 0, $w, $h, $color, $font, $iniziali); else : $image = explode('"', $args['data1']); $image = $image[1]; // Def del font $font = "assets/fonts/optimaltstd.ttf"; $dimension = 20; // Prendo l'icona $icon = imagecreatefrompng($image); $icon_width = imagesx($icon); $icon_height = imagesy($icon); $mid_icon = $icon_height / 2; $w = ($width / 2) - ($icon_width / 2); $h = ($height / 2) + ($mid_icon); imagecopy($immagine, $icon, $w, $h, 0, 0, $icon_width, $icon_height); // Inserimento testo $width1 = imagefontwidth($dimension) * strlen($text); $w=($width/2)-($width1/2); $h=$h+$icon_height-20; imagestring($immagine, $dimension, $w, $h, $text, $color); // Posizionamento if($text){ $h=(($height/2)+($icon_height/2))-50; } else { $h=($height/2)+$icon_height; } endif; imagepng($immagine, 'wp-content/themes/barberry-child/'.$date->format('d-m-Y--H-i-s').'dubl.jpeg'); $filename = $date->format('d-m-Y--H-i-s').'dubl.jpeg'; $imgpath = 'https://' . $_SERVER['SERVER_NAME']. '/wp-content/themes/barberry-child/' . $filename;
Dovrei passare $imgpath all’hook ‘woocommerce-after-cart-item’.
Grazie mille di eventuale risposta.
- Il topic ‘Passare una variabile all’interno di un hook ad un altro hook’ è chiuso a nuove risposte.