/** * This is a code snippet to import user membership data for both expirable and non-expiring * memberships for use with the "Import and export users and customers" plugin. * @link https://wordpress.org/plugins/import-users-from-csv-with-meta/ * * In your CSV import file, add a column for each membership as follows: * "_wpmem_products_" + "membership-slug". * (Get the slug from Memberships > All memberships) * * Example: if the membership slug is "my-simple-membership", then the column heading is: * "_wpmem_products_my-simple-membership". * * If the membership is a non-expiration membership, values are 1 for enabled, 0 for disabled * If the membership is an expiration membership, the expiration date MUST be YYYY-MM-DD. Any * other date format will not be read correctly and will cause an error. * * The script will adjust dates to the proper timestamp format and update the user's * membership array. */ add_action( 'post_acui_import_single_user', function( $headers, $data, $user_id ) { $memberships = wpmem_get_memberships(); foreach ( $headers as $i => $header ) { $membership_meta = substr( $header, 16 ); if ( array_key_exists( $membership_meta, $memberships ) ) { if ( 0 != $data[ $i ] ) { $expiration_period = ( isset( $memberships[ $membership_meta ]['expires'] ) ) ? $memberships[ $membership_meta ]['expires'] : false; $date = ( $expiration_period ) ? $data[ $i ] : false; wpmem_set_user_product( $membership_meta, $user_id, $date ); } else { wpmem_remove_user_product( $membership_meta, $user_id ); } } } }, 10, 3);
Not sure what to do with this code?
You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.
Here are some free articles to get you started:
- Using Code Snippets from the Site
- The functions.php File
- Create a plugin file for custom functions
- Create a child theme
- Do not modify plugin files!
For "hands on" help, consider a plugin support subscription or the Pro Bundle.