WordPress at Your Fingertips
function is not described

WC_Log_Handler_DB::add() protected WC 1.0

Add a log entry to chosen file.

{} It's a method of the class: WC_Log_Handler_DB{}

No Hooks.


true|false. True if write was successful.


$result = WC_Log_Handler_DB::add( $timestamp, $level, $message, $source, $context );
$timestamp(int) (required)
Log timestamp.
$level(string) (required)
$message(string) (required)
Log message.
$source(string) (required)
Log source. Useful for filtering and sorting.
$context(array) (required)
Context will be serialized and stored in database.

Code of WC_Log_Handler_DB::add() WC 5.8.0

protected static function add( $timestamp, $level, $message, $source, $context ) {
	global $wpdb;

	$insert = array(
		'timestamp' => date( 'Y-m-d H:i:s', $timestamp ),
		'level'     => WC_Log_Levels::get_level_severity( $level ),
		'message'   => $message,
		'source'    => $source,

	$format = array(
		'%s', // possible serialized context.

	if ( ! empty( $context ) ) {
		$insert['context'] = serialize( $context ); // @codingStandardsIgnoreLine.

	return false !== $wpdb->insert( "{$wpdb->prefix}woocommerce_log", $insert, $format );