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 ) );
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?
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
}
}
-
This reply was modified 3 years, 6 months ago by
Mihai Joldis.
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
}
}
?>