To write contents into a file using php:

Print array to file php:

Here array : $woocommerce

File name : filename-sample.txt

file_put_contents(‘filename-sample.txt’, print_r($woocommerce, true));