Reputation: 35
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
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