• Resolved rommelgracias

    (@rommelgracias)


    Hi,

    Im having a problem syncing date fields to Hubspot from WP Fusion. I have made sure the field is ‘date’ in the Contact Fields section. An example of the problem in the log is:

    membership_startdate: 1630368000000 → 163036800000000

    It seems like the wpf_format_field_value is adding extra zeros. The actual error message for this was:

    Error while updating meta data: Property values were not valid
    163036800000000 is more than 1,000 years ago or 1,000 years from now.

    These are the following filters I have regarding dates in my functions.php file:

    /* WP FUSION FILTERS AND FUNCTIONS */

    function my_wpf_filter_registration( $user_meta, $user_id ) {

    if ( isset( $_POST[ ‘membership-expiry’ ] ) ) {
    $user_meta[ ‘membership_enddate’ ] = $_POST[ ‘membership-expiry’ ];
    }

    return $user_meta;

    }

    add_filter( ‘wpf_user_register’, ‘my_wpf_filter_registration’, 10, 2 );

    function my_watch_meta_field( $fields ) {
    $fields[] = ‘membership_enddate’;
    $fields[] = ‘membership_startdate’;
    $fields[] = ‘membership_name’;
    $fields[] = ‘member_since’;
    $fields[] = ‘role’;

    return $fields;
    }
    add_filter( ‘wpf_watched_meta_fields’, ‘my_watch_meta_field’ );

    //AND

    function save_pmpro_level_to_meta( $level_id, $user_id ) {

    //get level information and post it to meta.
    $membership_data = pmpro_getMembershipLevelForUser( $user_id );

    $membership_id = $membership_data->ID;
    $membership_name = $membership_data->name;
    $membership_startdate = date( ‘d/m/Y’, $membership_data->startdate );
    $membership_enddate = $membership_data->enddate;

    if ( empty( $member_since ) ) {
    $member_since = date( ‘d/m/Y’, $membership_data->startdate );
    }

    // convert to date if not 0.
    if ( ‘0’ == $membership_enddate ) {
    $membership_enddate = ‘0’; //can change this to say ‘Never’ instead.
    } else {
    $membership_enddate = date( ‘d/m/Y’, $membership_enddate );
    }

    //update the user meta now.
    update_user_meta( $user_id, ‘membership_id’, $membership_id );
    update_user_meta( $user_id, ‘membership_name’, $membership_name );
    update_user_meta( $user_id, ‘membership_startdate’, $membership_startdate );
    update_user_meta( $user_id, ‘membership_enddate’, $membership_enddate );
    update_user_meta( $user_id, ‘member_since’, $member_since );

    }
    add_action( ‘pmpro_after_change_membership_level’, ‘save_pmpro_level_to_meta’, 10, 2 );

    If you can shed some light on my problem, I would really appreciate it as ive been struggling with it for a while.

    Thanks

Viewing 1 replies (of 1 total)
  • Plugin Author verygoodplugins

    (@verygoodplugins)

    Hey @rommelgracias ,

    Sorry for the delay on this, the notification didn’t come through for some reason.

    Can you check in your database and see how the dates are actually stored in the membership_startdate key?

    HubSpot dates are stored in milliseconds since the Unix Epoch (not seconds, which is a lot more common).

    When a field type is set to “date”, WP Fusion converts the date to a timestamp (in seconds), and then multiplies it by 1000 to get milliseconds. That’s why you’re seeing the extra 0’s appear.

    But, if the date is being correctly stored for the membership_startdate, that should all work automatically. It would only cause a problem if the membership_startdate was already in milliseconds, in which case it would get multiplied x1000 again, and you’d get an error like that.

    Cheers
    Jack

Viewing 1 replies (of 1 total)
  • The topic ‘Timestamp issue when syncing to Hubspot’ is closed to new replies.