2016-09-20 3 views
1

주문 후 WooCommerce 고맙습니다 페이지에 도달하면 파일에 쓰고 싶습니다. 나는 다음을 functions.php에 넣었습니다 :WooCommerce hook into 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()'는 부모 테마의 경로를 제공한다. –