Last active
April 28, 2023 09:06
-
-
Save mrmu/ab87723d54f720a6d603eeafa9660522 to your computer and use it in GitHub Desktop.
使用 woocommerce 內建的 wc logger,將 debug 用的 log 記錄到後台 WooCommerce / 狀態 / 記錄 裡。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * arg: | |
| * $msg: 要紀錄的內容,可用 string/array | |
| * $source_name: 此 log 的別名,方便於後台辨識 | |
| */ | |
| function my_wc_log($msg, $source_name) { | |
| if (function_exists('wc_get_logger')) { | |
| $log = wc_get_logger(); | |
| $log_context = array( 'source' => $source_name ); | |
| if (is_array($msg)) { | |
| $log->alert(wc_print_r( $msg, true ), $log_context); | |
| }else{ | |
| $log->log('info', $msg, $log_context); | |
| } | |
| }else{ | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
感謝大大分享!