Ho questo plugin che ho creato per caricare un'immagine prima che un ordine possa essere completato, ma per la vita di me non riesco a caricare l'immagine. $ _FILES non restituirà sempre nulla, non sono sicuro del perché comunque. Mi piacerebbe che il checkout non fosse completato fino a quando l'immagine non è stata caricata, è possibile? * Mi è stato detto che woocommerce utilizza Ajax per il carrelloC'è un modo per caricare un'immagine prima di completare il checkout senza un plug-in?
<?php
/*
@package UploadTest
@wordpress_plugin
Plugin Name: UploadTest
Plugin URI: null
Description:
Author: Goodship
Version: 0.0.2
Author URI: www.Goodship.co.za
*/
function add_image(){
$testLog = fopen(plugin_dir_path(__FILE__)."testicle.txt","w") or exit ("Unable to open file!");
//if they DID upload a file...
if($_FILES['testUpload']['name']){
//if no errors...
if(!$_FILES['testUpload']['error']){
//now is the time to modify the future file name and validate the file
$new_file_name = strtolower($_FILES['testUpload']['tmp_name']); //rename file
if($_FILES['testUpload']['size'] > (1024000)) //can't be larger than 1 MB
{
$valid_file = false;
$message = 'Oops! Your file\'s size is to large.';
}
//if the file has passed the test
if($valid_file){
//move it to where we want it to be
move_uploaded_file($_FILES['testUpload']['tmp_name'], plugin_dir_path(__FILE__).'uploads/'.$new_file_name);
$message = 'Congratulations! Your file was accepted.';
}
}
//if there is an error...
else
{
//set that to be the returned message
$message = 'Ooops! Your upload triggered the following error: '.$_FILES['testUpload']['error'];
}
}
fwrite ($testLog ,$message);
fwrite ($testLog ,var_dump($_FILES));
fclose ($testLog);
}
add_action('woocommerce_checkout_update_order_meta', 'add_image');
function add_checkout_notice() {
echo '<input type="file" name="testUpload" />';
}
add_action('woocommerce_checkout_before_customer_details', 'add_checkout_notice');
?>
stai inviando il modulo di verifica via ajax ?? –
Per il completamento del checkout basta usare JS per verificare se il campo di input dell'immagine è vuoto o meno. Se è vuoto metti un 'disabled' su un pulsante di pagamento completo, in modo che tu non possa completare il checkout. Quindi, una volta caricata l'immagine (presumo che JS debba essere coinvolto in qualche modo qui), basta rimuovere il 'disabled' dal pulsante checkout. Per quanto riguarda il motivo per cui non carica, nessun indizio ... –
@Maha Dev il checkout viene inviato normalmente, con qualsiasi processo woocommerce utilizza –