2016-09-20 25 views
1

注文後にWooCommerceのおはようページに達したときにファイルに書きたいと思います。私はfunctions.phpに次のように書いています:WooCommerceをwoocommerce_thankyouにフック

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

それはなぜ起きていないのですか?

+0

私はこの機能を自分自身でテストしていますが、それ自体は何もしません。したがって、** 'woocommerce_thankyou' **は何もしません。 – LoicTheAztec

+0

woocommerce_thankyou _ {$ order-> payment_method}でお支払い方法を交換してみてください。 – user3040610

答えて

2

ファイルを書き込むためにファイルのパスを追加する必要があります。ここに解決策があります:

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

子テーマを使用している場合、 'get_template_directory()'は親テーマのパスを提供します。 –

関連する問題