Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce加入WooCommerce谢谢_Php_Wordpress_Woocommerce_Hook Woocommerce - Fatal编程技术网

Php WooCommerce加入WooCommerce谢谢

Php WooCommerce加入WooCommerce谢谢,php,wordpress,woocommerce,hook-woocommerce,Php,Wordpress,Woocommerce,Hook Woocommerce,我想在下单后到达WooCommerce Thankyu页面时写入文件。我将以下内容放在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

我想在下单后到达WooCommerce Thankyu页面时写入文件。我将以下内容放在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);
}

它没有启动,我想知道为什么会这样?

您必须添加文件路径才能写入文件。以下是解决方案:

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

也许你应该在之前定义路径文件…我自己测试了这个函数,但它什么也没做。所以,
woocommerce\u thankyou
什么都不做是正常的。尝试用woocommerce\u thankyou{$order->payment\u method}钩子替换你的支付方法。如果你使用的是子主题,那么
get\u template\u directory()
为你提供其父主题的路径。