1. Home
  2. Hooks for Print & CSV data export

Hooks for Print & CSV data export

How can I modify the Print Page Title?

Hook
wcap_abandoned_carts_print_title

Usage:

add_filter( 'wcap_abandoned_carts_print_title', 'modify_print_title', 10, 1 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function modify_print_title( $title ) {
        $title = 'Abandoned Carts Print';
        return $title;
}

add_filter( 'wcap_abandoned_carts_print_title', 'modify_print_title', 10, 1 );

How can I modify Print Column Headers?

Hook
wcap_abandoned_carts_print_columns

Usage:

add_filter( 'wcap_abandoned_carts_print_columns', 'modify_print_cols', 10, 1 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function modify_print_cols( $cols ) {
	$cols['user_name'] = 'First Name';
	return $cols;
}
add_filter( 'wcap_abandoned_carts_print_columns', 'modify_print_cols', 10, 1 );

How can I modify Print Column Data for one row at a time?

Hook
wcap_abandoned_carts_print_row_data

Usage:

add_filter( 'wcap_abandoned_carts_print_row_data', 'modify_print_row', 10, 2 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function modify_print_row( $row, $val ) {

	// Remove the  tag.
	$row = str_ireplace( '', '', $row );
	$user_id = $val->user_id;
	$user_type = $val->customer;
	if ( stripos( $user_type, 'GUEST' ) > 0 ) {
		$guest_details = wcap_get_data_guest_history( $user_id );
		$first_name = $guest_details->billing_first_name;
	} else {
		$first_name = 'WP User';
	}
        // Concatenate the data to row data.
	$row .= "" . $first_name . '';
	$row .= ''; // Add the  back.
	return $row;
}
add_filter( 'wcap_abandoned_carts_print_row_data', 'modify_print_row', 10, 2 );

How can I modify Print Column Data for all the rows in one go?

Hook
wcap_abandoned_carts_print_rows

Usage:

add_filter( 'wcap_abandoned_carts_print_rows', 'modify_print_data', 10, 2 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function modify_print_data( $print_data, $cart_details ) {
        $print_data = '';
        foreach ( $cart_details as $k => $v ) {
               // Start the row.
               $print_data .= "";
 
               // loop and prepare data as needed.
               $print_data .= "$col1";
               $print_data .= "$col2";
               $print_data .= "$col3";

               // Close the row.
               $print_data .= "";
        }
        return $print_data;
}
add_filter( 'wcap_abandoned_carts_print_rows', 'modify_print_data', 10, 2 );

How can I modify CSV file name?

Hook
wcap_csv_file_name

Usage:

add_filter( 'wcap_csv_file_name', 'modify_csv_file_name', 10, 1 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function modify_csv_file_name( $name ) {
	$name = 'test-name-change.csv';
	return $name;
}
add_filter( 'wcap_csv_file_name', 'modify_csv_file_name', 10, 1 );

How can I modify CSV Column Headers?

Hook
wcap_abandoned_carts_csv_columns

Usage:

add_filter( 'wcap_abandoned_carts_csv_columns', 'modify_csv_cols', 10, 1 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function modify_csv_cols( $cols ) {
	$cols['user_name'] = 'First Name';
	return $cols;
}
add_filter( 'wcap_abandoned_carts_csv_columns', 'modify_csv_cols', 10, 1 );

How can I modify CSV Column Data one row at a time?

Hook
wcap_abandoned_carts_csv_row_data

Usage:

add_filter( 'wcap_abandoned_carts_csv_row_data', 'modify_csv_row', 10, 2 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
public static function modify_csv_row( $row, $val ) {
        // $val contains the individual cart record from the plugin table. 
	$user_id = $val->user_id;
	$user_type = $val->customer;
	if ( stripos( $user_type, 'GUEST' ) > 0 ) { // If it's a guest user, fetch data using plugin functions.
		$guest_details = wcap_get_data_guest_history( $user_id );
		$first_name = $guest_details->billing_first_name;
	} else { // use WP User functions to fetch the information.
		$first_name = 'WP User'; // hard coded example here
	}
        // Concatenate data to the row.
	$row .= ',' . "\" $first_name \"";
	return $row;
}
add_filter( 'wcap_abandoned_carts_csv_row_data', 'modify_csv_row', 10, 2 );

How can I modify CSV Column Data for all the rows at one go?

Hook
wcap_abandoned_carts_csv_data

Usage:

add_filter( 'wcap_abandoned_carts_csv_data', 'modify_csv_data', 10, 2 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function modify_csv_data( $csv_data, $cart_details ) {
        $csv = '';
        foreach ( $cart_details as $k => $v ) {
               // loop and prepare data as needed.
               $csv .= $col1 . ',' . $col2 . ',' . $col3;
               $csv .= "\n";
        }
        return $csv;
}
add_filter( 'wcap_abandoned_carts_csv_data', 'modify_csv_data', 10, 2 );
Was this article helpful to you? Yes No

How can we help?