alexkwatson
alexkwatson

Reputation: 35

WooCommerce hook into woocommerce_thankyou

I want to write to a file when the WooCommerce thankyou page is reached after placing an order. I put the following in functions.php:

add_action( 'woocommerce_thankyou', 'test_1', 10, 1 );

function test_1(){
  //write to a file when this function is run
  $contents = date('m/d/Y h:i:s a', time());
  file_put_contents('test.txt', $contents);
}

It does not fire and I am wondering why that is?

Upvotes: 1

Views: 3178

Answers (1)

Manish Suthar
Manish Suthar

Reputation: 48

You have to add file's path for write the file. Here is solution:

add_action( 'woocommerce_thankyou', 'test_1', 10, 1 );
function test_1(){
   // write to a file when this function is run
   $contents = date('m/d/Y h:i:s a', time());
   $pathoffile = get_template_directory()."/test/test.txt";
   file_put_contents($pathoffile, $contents, FILE_APPEND);
}

Upvotes: 2

Related Questions