Woocommerce update order hook “save_post” not allowing file saves
up vote
0
down vote
favorite
So I find this strange but maybe someone can help.
I need to save an incoming file from a remote server when the admin of the wordpress website updates the order in the backend.
The hook I'm using is
add_action( 'save_post', 'courier_save_wc_order_fields', 10, 2 );
Now everything works fine and I can update the post_meta as I need.
When it comes to saving an incoming PDF file things go south.
inside this perticular hook (only one I have ever found) I cannot save files.
Is this because this is when woocommerce is about to save to DB?
I've even stripped out all other code and left it as
add_action( 'save_post', 'courier_save_wc_order_fields', 10, 2 );
function courier_save_wc_order_fields( $post_id ) {
file_put_contents('incommingdata.txt', print_r("This is random text",true));
}
Again, this is the only place this happens..
Is there a better hook that I won't have this issue?
I need one that checks a meta_box value in the Admin order page and updates the order meta accordingly while communicating to a remote server to save and retrieve a file.... Everything works except for this file saving.
Side note:
$path="my_file_received.pdf"
$decodedString = base64_decode($base64string);
$fileHandle = fopen($path, "w");
if ($fileHandle) {
fwrite($fileHandle, $decodedString);
fclose($fileHandle);
return 1;
}
Does not show an error yet the file does not exist either.
php wordpress woocommerce
add a comment |
up vote
0
down vote
favorite
So I find this strange but maybe someone can help.
I need to save an incoming file from a remote server when the admin of the wordpress website updates the order in the backend.
The hook I'm using is
add_action( 'save_post', 'courier_save_wc_order_fields', 10, 2 );
Now everything works fine and I can update the post_meta as I need.
When it comes to saving an incoming PDF file things go south.
inside this perticular hook (only one I have ever found) I cannot save files.
Is this because this is when woocommerce is about to save to DB?
I've even stripped out all other code and left it as
add_action( 'save_post', 'courier_save_wc_order_fields', 10, 2 );
function courier_save_wc_order_fields( $post_id ) {
file_put_contents('incommingdata.txt', print_r("This is random text",true));
}
Again, this is the only place this happens..
Is there a better hook that I won't have this issue?
I need one that checks a meta_box value in the Admin order page and updates the order meta accordingly while communicating to a remote server to save and retrieve a file.... Everything works except for this file saving.
Side note:
$path="my_file_received.pdf"
$decodedString = base64_decode($base64string);
$fileHandle = fopen($path, "w");
if ($fileHandle) {
fwrite($fileHandle, $decodedString);
fclose($fileHandle);
return 1;
}
Does not show an error yet the file does not exist either.
php wordpress woocommerce
What have you tried to debug the problem? Usually, there should be an error message. If not, try using a higher error reporting level. Have you checked all file permissions?
– Nico Haase
Nov 9 at 15:16
It's only this hook, any other works fine. error_reporting(E_ALL); and error_reporting(-1); produce no errors ..
– Miguel Carneiro
Nov 9 at 15:37
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
So I find this strange but maybe someone can help.
I need to save an incoming file from a remote server when the admin of the wordpress website updates the order in the backend.
The hook I'm using is
add_action( 'save_post', 'courier_save_wc_order_fields', 10, 2 );
Now everything works fine and I can update the post_meta as I need.
When it comes to saving an incoming PDF file things go south.
inside this perticular hook (only one I have ever found) I cannot save files.
Is this because this is when woocommerce is about to save to DB?
I've even stripped out all other code and left it as
add_action( 'save_post', 'courier_save_wc_order_fields', 10, 2 );
function courier_save_wc_order_fields( $post_id ) {
file_put_contents('incommingdata.txt', print_r("This is random text",true));
}
Again, this is the only place this happens..
Is there a better hook that I won't have this issue?
I need one that checks a meta_box value in the Admin order page and updates the order meta accordingly while communicating to a remote server to save and retrieve a file.... Everything works except for this file saving.
Side note:
$path="my_file_received.pdf"
$decodedString = base64_decode($base64string);
$fileHandle = fopen($path, "w");
if ($fileHandle) {
fwrite($fileHandle, $decodedString);
fclose($fileHandle);
return 1;
}
Does not show an error yet the file does not exist either.
php wordpress woocommerce
So I find this strange but maybe someone can help.
I need to save an incoming file from a remote server when the admin of the wordpress website updates the order in the backend.
The hook I'm using is
add_action( 'save_post', 'courier_save_wc_order_fields', 10, 2 );
Now everything works fine and I can update the post_meta as I need.
When it comes to saving an incoming PDF file things go south.
inside this perticular hook (only one I have ever found) I cannot save files.
Is this because this is when woocommerce is about to save to DB?
I've even stripped out all other code and left it as
add_action( 'save_post', 'courier_save_wc_order_fields', 10, 2 );
function courier_save_wc_order_fields( $post_id ) {
file_put_contents('incommingdata.txt', print_r("This is random text",true));
}
Again, this is the only place this happens..
Is there a better hook that I won't have this issue?
I need one that checks a meta_box value in the Admin order page and updates the order meta accordingly while communicating to a remote server to save and retrieve a file.... Everything works except for this file saving.
Side note:
$path="my_file_received.pdf"
$decodedString = base64_decode($base64string);
$fileHandle = fopen($path, "w");
if ($fileHandle) {
fwrite($fileHandle, $decodedString);
fclose($fileHandle);
return 1;
}
Does not show an error yet the file does not exist either.
php wordpress woocommerce
php wordpress woocommerce
asked Nov 9 at 15:13
Miguel Carneiro
286
286
What have you tried to debug the problem? Usually, there should be an error message. If not, try using a higher error reporting level. Have you checked all file permissions?
– Nico Haase
Nov 9 at 15:16
It's only this hook, any other works fine. error_reporting(E_ALL); and error_reporting(-1); produce no errors ..
– Miguel Carneiro
Nov 9 at 15:37
add a comment |
What have you tried to debug the problem? Usually, there should be an error message. If not, try using a higher error reporting level. Have you checked all file permissions?
– Nico Haase
Nov 9 at 15:16
It's only this hook, any other works fine. error_reporting(E_ALL); and error_reporting(-1); produce no errors ..
– Miguel Carneiro
Nov 9 at 15:37
What have you tried to debug the problem? Usually, there should be an error message. If not, try using a higher error reporting level. Have you checked all file permissions?
– Nico Haase
Nov 9 at 15:16
What have you tried to debug the problem? Usually, there should be an error message. If not, try using a higher error reporting level. Have you checked all file permissions?
– Nico Haase
Nov 9 at 15:16
It's only this hook, any other works fine. error_reporting(E_ALL); and error_reporting(-1); produce no errors ..
– Miguel Carneiro
Nov 9 at 15:37
It's only this hook, any other works fine. error_reporting(E_ALL); and error_reporting(-1); produce no errors ..
– Miguel Carneiro
Nov 9 at 15:37
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
So I found the answer to my issue...
The save_post
hook has a different URL than other hooks that I have used..
So when I normally used file_put_contents('incommingdata.txt', print_r("This is random text",true));
I would always get the file saved within my plugin folder or theme folder or the base url.
The url for this hook is the wp-admin folder and not the base domain or plugin folder.
to fix this and make sure I save in the right folder the solution is:
$this_dir_of_my_file = dirname(__FILE__);
$this_dir_of_my_file = $this_dir_of_my_file . "/Example.txt";
file_put_contents($this_dir_of_mine, print_r("This is random text in my file.",true));
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
So I found the answer to my issue...
The save_post
hook has a different URL than other hooks that I have used..
So when I normally used file_put_contents('incommingdata.txt', print_r("This is random text",true));
I would always get the file saved within my plugin folder or theme folder or the base url.
The url for this hook is the wp-admin folder and not the base domain or plugin folder.
to fix this and make sure I save in the right folder the solution is:
$this_dir_of_my_file = dirname(__FILE__);
$this_dir_of_my_file = $this_dir_of_my_file . "/Example.txt";
file_put_contents($this_dir_of_mine, print_r("This is random text in my file.",true));
add a comment |
up vote
0
down vote
accepted
So I found the answer to my issue...
The save_post
hook has a different URL than other hooks that I have used..
So when I normally used file_put_contents('incommingdata.txt', print_r("This is random text",true));
I would always get the file saved within my plugin folder or theme folder or the base url.
The url for this hook is the wp-admin folder and not the base domain or plugin folder.
to fix this and make sure I save in the right folder the solution is:
$this_dir_of_my_file = dirname(__FILE__);
$this_dir_of_my_file = $this_dir_of_my_file . "/Example.txt";
file_put_contents($this_dir_of_mine, print_r("This is random text in my file.",true));
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
So I found the answer to my issue...
The save_post
hook has a different URL than other hooks that I have used..
So when I normally used file_put_contents('incommingdata.txt', print_r("This is random text",true));
I would always get the file saved within my plugin folder or theme folder or the base url.
The url for this hook is the wp-admin folder and not the base domain or plugin folder.
to fix this and make sure I save in the right folder the solution is:
$this_dir_of_my_file = dirname(__FILE__);
$this_dir_of_my_file = $this_dir_of_my_file . "/Example.txt";
file_put_contents($this_dir_of_mine, print_r("This is random text in my file.",true));
So I found the answer to my issue...
The save_post
hook has a different URL than other hooks that I have used..
So when I normally used file_put_contents('incommingdata.txt', print_r("This is random text",true));
I would always get the file saved within my plugin folder or theme folder or the base url.
The url for this hook is the wp-admin folder and not the base domain or plugin folder.
to fix this and make sure I save in the right folder the solution is:
$this_dir_of_my_file = dirname(__FILE__);
$this_dir_of_my_file = $this_dir_of_my_file . "/Example.txt";
file_put_contents($this_dir_of_mine, print_r("This is random text in my file.",true));
answered Nov 12 at 14:22
Miguel Carneiro
286
286
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228385%2fwoocommerce-update-order-hook-save-post-not-allowing-file-saves%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What have you tried to debug the problem? Usually, there should be an error message. If not, try using a higher error reporting level. Have you checked all file permissions?
– Nico Haase
Nov 9 at 15:16
It's only this hook, any other works fine. error_reporting(E_ALL); and error_reporting(-1); produce no errors ..
– Miguel Carneiro
Nov 9 at 15:37