Wordpress Export WooCommerce Memberships End Date

20 Views Asked by At

I am trying to export WooCommerce Memberships End Date in Wp All Export.

I believe this is stored in an array like so ..

wc_memberships_get_user_memberships -> get_end_date()

I have attempted a Custom Function as follows

// Function to get end date of each membership and export using WP All Export
function export_membership_end_dates() {
    // Get memberships for the current user.
    $memberships = wc_memberships_get_user_memberships();

    // Verify that the user has some memberships.
    if ( $memberships ) {
        $end_dates = array(); // Array to store end dates

        foreach ( $memberships as $membership ) {
            // Get the end date for each membership
            $end_date = $membership->get_end_date();
            
            // If end date is serialized, unserialize it
            if ( is_serialized( $end_date ) ) {
                $end_date = unserialize( $end_date );
                // Assuming end date is stored as Unix timestamp in the serialized array
                $end_date = date( 'Y-m-d H:i:s', $end_date['date'] );
            }

            // Store end date in array
            $end_dates[] = $end_date;
        }

        // Export the end dates using WP All Export
        return implode( ',', $end_dates );
    }

    return ''; // No memberships found
}

// Register the export function with WP All Export
add_filter( 'wp_all_export_csv_cell', 'export_membership_end_dates', 10, 2 );

And then added a custom Export Field like so

('export_membership_end_dates'())

Unfortunately i am getting "An Error Occurred" message.

To be honest the aforementioned was a an unlucky stab in the dark, but i would greatly appreciate any direction on this.

0

There are 0 best solutions below