मेरे पास यह प्लगइन है जिसे मैंने एक ऑर्डर पूरा करने से पहले एक छवि अपलोड करने के लिए बनाया है, लेकिन मेरे जीवन के लिए मैं छवि को अपलोड करने के लिए नहीं मिल सकता। $ _FILES हमेशा कुछ भी नहीं लौटेगा, मुझे यकीन नहीं है कि क्यों। मैं यह चाहता हूं कि जब तक छवि अपलोड नहीं हो जाती तब तक चेकआउट पूरा नहीं होगा, क्या यह भी संभव है? * मुझे बताया गया है कि woocommerce गाड़ीप्लगइन के बिना चेकआउट पूर्ण होने से पहले कोई छवि अपलोड करने का कोई तरीका है?
<?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');
?>
क्या आप AJAX के माध्यम से चेकआउट फॉर्म सबमिट कर रहे हैं ?? –
चेकआउट पूर्ण होने के लिए बस यह जांचने के लिए जेएस का उपयोग करें कि छवि का इनपुट फ़ील्ड खाली है या नहीं। यदि यह खाली है तो एक पूर्ण चेकआउट बटन पर 'अक्षम' डालें, ताकि आप चेकआउट को पूरा नहीं कर सकें। फिर एक बार जब आप छवि अपलोड कर लेंगे (मुझे लगता है कि जेएस किसी भी तरह से शामिल होना चाहिए), बस चेकआउट बटन से 'अक्षम' को हटा दें। क्यों यह अपलोड नहीं होता है, इसके लिए कोई संकेत नहीं है ... –
@ माहा देव चेकआउट सामान्य रूप से सबमिट किया जाता है, जो भी प्रक्रिया woocommerce का उपयोग करता है –