Advertisement
palsushobhan

Vendor Registration Date

Mar 26th, 2024
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. add_shortcode( 'vendor_registration_date', 'vendor_registration_date_shortcode' );
  2.  
  3. function vendor_registration_date_shortcode( $attr ) {
  4.    global $post;
  5.    $store_id = '';
  6.    if ( isset( $attr['id'] ) && ! empty( $attr['id'] ) ) {
  7.        $store_id = absint( $attr['id'] );
  8.    }
  9.    if ( wcfm_is_store_page() ) {
  10.        $wcfm_store_url = get_option( 'wcfm_store_url', 'store' );
  11.        $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
  12.        $store_id = 0;
  13.        if ( ! empty( $store_name ) ) {
  14.            $store_user = get_user_by( 'slug', $store_name );
  15.            $store_id = $store_user->ID;
  16.        }
  17.    }
  18.    if ( is_product() ) {
  19.        $store_id = $post->post_author;
  20.    }
  21.    if( !$store_id ) return;
  22.    $register_on = abs( get_user_meta( $store_id, 'wcfm_register_on', true ) );
  23.    $today = strtotime( "now" );
  24.    $diff = abs( $today - $register_on );
  25.    $years = floor( $diff / (365 * 24 * 60 * 60) );
  26.    $months = floor( ($diff - $years * 365 * 24 * 60 * 60) / (30 * 24 * 60 * 60) );
  27.    $days = floor( ($diff - $years * 365 * 24 * 60 * 60 - $months * 30 * 24 * 60 * 60) / (24 * 60 * 60) );
  28.    $total_duration = '';
  29.    if ( $years || $months || $days ) {
  30.        if ( $years )
  31.            $total_duration .= sprintf( _n( '%s year ', '%s years ', $years ), $years );
  32.        if ( $months )
  33.            $total_duration .= sprintf( _n( '%s month ', '%s months ', $months ), $months );
  34.        if ( $days )
  35.            $total_duration .= sprintf( _n( '%s day ', '%s days ', $days ), $days );
  36.        return sprintf( 'Joined %sago', $total_duration );
  37.    }
  38.    return 'Joined Today';
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement