• Resolved Sho-Down

    (@sho-down)


    I’m setting up an Account page for customers and I like how you guys did the EDD website’s account dashboard. Is there a code/function for “Customer Since” that outputs a formatted date?

    I found the code for number of total purchases:
    <?php echo edd_count_purchases_of_customer(); ?>

    And the code for total value of purchases on Andrew’s site from 2015 (is there an easier way to output this besides using Andrew’s method?):
    https://andrew.dev/easy-digital-downloads-show-how-much-customer-has-spent

    I just can’t find the code for Customer Since. Thanks!

    • This topic was modified 2 years, 1 month ago by Sho-Down.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Mihai Joldis

    (@misulicus)

    Hey @sho-down

    For the Customer since field, you can use the $custoner->date_created method.
    Perhaps something like this to get the date:

    
    $customer_since_date = substr( $customer->date_created, 0, strpos( $customer->date_created, ' ' ) );
    $customer_since = date( 'F j, Y', str_replace( '-', '/', strtotime( $customer_since_date ) ) );
    

    Something similar can be done for the purchase value as that is now stored in the Customer table:

    
    echo edd_currency_filter( edd_format_amount( $customer->purchase_value ) );
    
    Thread Starter Sho-Down

    (@sho-down)

    ah that’s a bit over my head @misulicus, I could use little more help if you wouldn’t mind, if not I understand.

    I don’t know how to put that in my custom template page file for it to output the formatted date. I can’t do:

    <?php $customer_since_date = substr( $customer->date_created, 0, strpos( $customer->date_created, ' ' ) );
    $customer_since = date( 'F j, Y', str_replace( '-', '/', strtotime( $customer_since_date ) ) );
    ?>

    I looked in customers.php and found this but it outputs December 31, 1969:

    <span class="customer-since info-item editable">
    <?php printf(
    /* translators: The date. */
    esc_html__( '%s', 'easy-digital-downloads' ),
    esc_html( edd_date_i18n( $customer->date_created ) )
    ); ?>
    </span>

    And this just outputs $0.00:

    <?php echo edd_currency_filter( edd_format_amount( $customer->purchase_value ) ); ?>

    Do I need to put some code in my functions.php file and call it from there?

    Plugin Support Mihai Joldis

    (@misulicus)

    Hey @sho-down

    You will need to get the $customer object first in order to access that data. Posting a code snippet below but you might need to adjust it based on your needs.
    If you need assistance with this is best to reach out to a developer:

    
    $customer = '';
    if ( is_user_logged_in() ) {
    	$current_user = wp_get_current_user();
    
    	if ( class_exists( 'Easy_Digital_Downloads' ) ) {
    		$customer = new EDD_Customer( $current_user->ID, true );
    	}
    	
    	if ( ! empty( $customer->id ) ) {
    		$customer_since_date = substr( $customer->date_created, 0, strpos( $customer->date_created, ' ' ) );
    		$customer_since = date( 'F j, Y', str_replace( '-', '/', strtotime( $customer_since_date ) ) );
    	
    		echo $customer_since; //This prints the Customer creation date
    
    		echo edd_currency_filter( edd_format_amount( $customer->purchase_value ) ); // This prints the customer's purchase value
    	}
    }
    
    Thread Starter Sho-Down

    (@sho-down)

    Thanks so much @misulicus that works in my page template, I just had to add an additional bracket at the end:

    <?php $customer = ''; ?>
    <?php if ( is_user_logged_in() ) {
    	$current_user = wp_get_current_user();
    
    	if ( class_exists( 'Easy_Digital_Downloads' ) ) {
    		$customer = new EDD_Customer( $current_user->ID, true );
    	}
    	
    	if ( ! empty( $customer->id ) ) {
    		$customer_since_date = substr( $customer->date_created, 0, strpos( $customer->date_created, ' ' ) );
    		$customer_since = date( 'F j, Y', str_replace( '-', '/', strtotime( $customer_since_date ) ) );
    	
    		echo $customer_since; //This prints the Customer creation date
    
    		echo edd_currency_filter( edd_format_amount( $customer->purchase_value ) ); // This prints the customer's purchase value
    	}
    }
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘“Customer Since” code/function that outputs the date?’ is closed to new replies.