Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
for ( $i = 0; $i < $no_of_pages; $i++) {
// Adds a page to put the data in.
$document->add_page();
// Goes through each label (for each item).
for ( $j = 0; $j < $labels_per_page; $j++ ) {
/*
* Some variables to be used later.
* The values will be put later.
*/
$index2 = $j + 1;
$mem = array();
$name = array();
$address_line1 = array();
$address_line2 = array();
$city_state = array();
$country = array();
if ( isset( $expiring_members[ $index ] ) ) {
// Gets user data for the expiring member.
$userdata = get_userdata( $expiring_members[ $index ]->post_author );
if ( $membership_number = get_user_meta( $expiring_members[ $index ]->post_author, 'wpcf-membership-number', true ) ) {
$mem[] = $membership_number;
}
$mem[] = $userdata->user_login;
$mem[] = date( 'Y.m' );
// Puts membership data in variables.
if ( isset( $userdata->first_name ) ) {
$name[] = $userdata->first_name;
}
if ( isset( $userdata->last_name ) ) {
$name[] = $userdata->last_name;
}
if ( isset( $userdata->billing_address_1 ) ) {
$address_line1[] = $userdata->billing_address_1;
}
if ( isset( $userdata->billing_address_2 ) && !empty( $userdata->billing_address_2 ) ) {
$address_line2[] = $userdata->billing_address_2;
}
if ( isset( $userdata->billing_city ) ) {
$city_state[] = $userdata->billing_city;
}
if ( isset( $userdata->billing_state ) ) {
$state = $userdata->billing_state;
if ( isset( $userdata->billing_postcode ) ) {
$state .= ' ' . $userdata->billing_postcode;
}
$city_state[] = $state;
}
if ( isset( $userdata->billing_country ) && strtolower( $userdata->billing_country ) != 'usa' && strtolower( $userdata->billing_country ) != 'us' ) {
$country[] = isset( $countries[$userdata->billing_country] ) ? $countries[$userdata->billing_country] : $userdata->billing_country;
}
}
// Puts membership data on the DOCX.
$document->setValue( 'mem' . $index2, strtoupper( implode( ' ', $mem ) ) );
$document->setValue( 'name' . $index2, strtoupper( implode( ' ', $name ) ) );
$document->setValue( '1st_address_line' . $index2, strtoupper( implode( ' ', $address_line1 ) ) );
/*
* If address line 2 is empty we will print the country in its place
* and blank in country row.
*/
if ( !empty( $address_line2 ) ) {
$document->setValue( '2nd_address_line' . $index2, strtoupper( implode( ' ', $address_line2 ) ) );
$document->setValue( 'city_state' . $index2, strtoupper( implode( ', ', $city_state ) ) );
$document->setValue( 'country' . $index2, strtoupper( implode( ', ', $country ) ) );
}else{
$document->setValue( '2nd_address_line' . $index2, strtoupper( implode( ', ', $city_state ) ) );
$document->setValue( 'city_state' . $index2, strtoupper( implode( ', ', $country ) ) );
$document->setValue( 'country' . $index2, '');
}
$index++;
}
}
// Saves the output file.
$document->save( $save_path );
// To give the export file a name to have after download.
header( "location: " . $save_url );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.