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.










share|improve this question






















  • 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















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.










share|improve this question






















  • 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













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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));





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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));





    share|improve this answer

























      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));





      share|improve this answer























        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));





        share|improve this answer












        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));






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 14:22









        Miguel Carneiro

        286




        286






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Schultheiß

            Liste der Kulturdenkmale in Wilsdruff

            Android Play Services Check