Php WooCommerce加入WooCommerce谢谢
我想在下单后到达WooCommerce Thankyu页面时写入文件。我将以下内容放在functions.php中: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
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()
为你提供其父主题的路径。