Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode( 'vendor_registration_date', 'vendor_registration_date_shortcode' );
- function vendor_registration_date_shortcode( $attr ) {
- global $post;
- $store_id = '';
- if ( isset( $attr['id'] ) && ! empty( $attr['id'] ) ) {
- $store_id = absint( $attr['id'] );
- }
- if ( wcfm_is_store_page() ) {
- $wcfm_store_url = get_option( 'wcfm_store_url', 'store' );
- $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
- $store_id = 0;
- if ( ! empty( $store_name ) ) {
- $store_user = get_user_by( 'slug', $store_name );
- $store_id = $store_user->ID;
- }
- }
- if ( is_product() ) {
- $store_id = $post->post_author;
- }
- if( !$store_id ) return;
- $register_on = abs( get_user_meta( $store_id, 'wcfm_register_on', true ) );
- $today = strtotime( "now" );
- $diff = abs( $today - $register_on );
- $years = floor( $diff / (365 * 24 * 60 * 60) );
- $months = floor( ($diff - $years * 365 * 24 * 60 * 60) / (30 * 24 * 60 * 60) );
- $days = floor( ($diff - $years * 365 * 24 * 60 * 60 - $months * 30 * 24 * 60 * 60) / (24 * 60 * 60) );
- $total_duration = '';
- if ( $years || $months || $days ) {
- if ( $years )
- $total_duration .= sprintf( _n( '%s year ', '%s years ', $years ), $years );
- if ( $months )
- $total_duration .= sprintf( _n( '%s month ', '%s months ', $months ), $months );
- if ( $days )
- $total_duration .= sprintf( _n( '%s day ', '%s days ', $days ), $days );
- return sprintf( 'Joined %sago', $total_duration );
- }
- return 'Joined Today';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement