WC_Customer_Download_Log_Data_Store::create( WC_Customer_Download_Log $download_log )

Create download log entry.


Description Description


Parameters Parameters

$download_log

(Required) Customer download log object.


Top ↑

Source Source

File: includes/data-stores/class-wc-customer-download-log-data-store.php

	public function create( WC_Customer_Download_Log &$download_log ) {
		global $wpdb;

		// Always set a timestamp.
		if ( is_null( $download_log->get_timestamp( 'edit' ) ) ) {
			$download_log->set_timestamp( time() );
		}

		$data = array(
			'timestamp'       => date( 'Y-m-d H:i:s', $download_log->get_timestamp( 'edit' )->getTimestamp() ),
			'permission_id'   => $download_log->get_permission_id( 'edit' ),
			'user_id'         => $download_log->get_user_id( 'edit' ),
			'user_ip_address' => $download_log->get_user_ip_address( 'edit' ),
		);

		$format = array(
			'%s',
			'%s',
			'%s',
			'%s',
		);

		$result = $wpdb->insert(
			$wpdb->prefix . self::get_table_name(),
			apply_filters( 'woocommerce_downloadable_product_download_log_insert_data', $data ),
			apply_filters( 'woocommerce_downloadable_product_download_log_insert_format', $format, $data )
		);

		do_action( 'woocommerce_downloadable_product_download_log_insert', $data );

		if ( $result ) {
			$download_log->set_id( $wpdb->insert_id );
			$download_log->apply_changes();
		} else {
			wp_die( esc_html__( 'Unable to insert download log entry in database.', 'woocommerce' ) );
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.