• Resolved growsmartehg

    (@growsmartehg)


    Hello there,

    I have purchased your WPSlice Pro Plugin and want to work with Lead commissions. I don’t have Ninja or Gravity form, because I powered my Elementor form with Action Pack. Furthermore, I have created via custom PHP in functions.php to give the affiliate ID via url like http://www.easyhomegrowing.com/?affiliate_id=123 to every user who registers on our webpage. I have created a custom field for the user to be able to transfer this information via webhook/API to WPSlice (after verification of this contact).

    I don’t see any settings for Lead commissions in the backend. Is that because I don’t have a form plugin you use activated? I don’t want to change our forms to Ninja or Gravity. I am very good in custom solutions and if this is not possible I need to restore the purchase within the money back timeframe.

    So my questions:

    How do I set up the lead commissions rate for leads? I don’t see the setting under SliceWP > Settings > General > Commissions Settings > Lead Rate for setting up the lead commissions.


    And how should the workflow look like when sending the data to WPSlice?



    Thank you very much for answering my questions,
    best regards, Tobias

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter growsmartehg

    (@growsmartehg)

    I was able to add a user after formsubmit via custom PHP code to an affiliate via URL parameter. Now I am struggling with creating a lead. I am wondering if SliceWP plugin has a build n function to generate a lead like slicewp_add_lead() or a function to set up a commission like slicewp_add_commission()

    In your documentation you have a lot of get-functions for retrieving data. If you can procide me the code for creating a lead and creating a tcommission that would help me a lot and I have solved this problem or at least I made big steps.

    Plugin Author iova.mihai

    (@iovamihai)

    Hey @growsmartehg,

    Thank you for reaching out! The lead commission settings do not appear because you have no active integration that supports lead commissions (considering that the Gravity Forms and Ninja Forms ones are disabled). Considering that you’re building a custom solution, you could just enable one of these integrations to have the settings appear.

    Also, to add a new lead, please use this function: slicewp_insert_lead( $lead_data_array )

    All of our add functions are named “insert”. So, to add different objects, like affiliates, commissions, etc., you can use the functions slicewp_insert_affiliate( $affiliate_data_array ), slicewp_insert_commission( $commission_data_array ), etc.

    Thank you and best wishes,

    Mihai

    Thread Starter growsmartehg

    (@growsmartehg)

    Thank you a lot. I have managed everything so far.

    When I inserted the lead via PHP code from formregistration to SliceWP the Date is “-0001-11-30 02:00” and not the current time. I have tried to modify the code so the real date is beeing used but I was unable to do so. Also I can not insert the original URL into entry, maybe it is the same problem with the date. But I was able to transfert the register e-mail to customer, so I believe the solution is just a little changement. Here is my code for that, maybe you can tell me where the error is (please see under the section D Lead conversion to SliceWP):

    Thanks a lot!

    Cheers, Tobias

    <?php
    /**

    • Source Information & Lead Conversion for WP-Slice (minimal parameter set).
      *
    • This code:
    • A) Registers and saves three meta fields (affiliate_id, platform_source, platform_medium).
    • B) Displays a custom “Source Information” section in the user profile.
    • C) Fills form fields on the frontend via URL (using JavaScript).
    • D) Immediately after registration, converts the visitor into a lead in WP-Slice,
    • if an affiliate_id is present – passing only the necessary parameters,
    • including a valid timestamp (formatted as “Y-m-d H:i” without seconds) and
    • the user’s email and the original URL in the “entry” field.
      */

    /* A1. Register meta fields officially */
    function my_register_source_meta_fields() {
    $fields = array(
    ‘affiliate_id’ => ‘Affiliate ID for tracking’,
    ‘platform_source’ => ‘Platform Source for tracking (e.g. META, YT, etc.)’,
    ‘platform_medium’ => ‘Platform Medium for tracking (e.g. Ads abc, Youtubevideo 22, etc.)’
    );
    foreach ( $fields as $key => $description ) {
    register_meta( ‘user’, $key, array(
    ‘type’ => ‘string’,
    ‘description’ => $description,
    ‘single’ => true,
    ‘show_in_rest’ => true,
    ) );
    }
    }
    add_action( ‘after_setup_theme’, ‘my_register_source_meta_fields’ );

    /* A2. Add fields to user contact methods (so external plugins like WP-Slice can detect them) */
    function add_custom_mautic_contactmethods_generic( $contactmethods ) {
    $fields = array(
    ‘affiliate_id’ => ‘Affiliate ID’,
    ‘platform_source’ => ‘Platform Source’,
    ‘platform_medium’ => ‘Platform Medium’
    );
    foreach ( $fields as $key => $label ) {
    $contactmethods[$key] = $label;
    }
    return $contactmethods;
    }
    add_filter( ‘user_contactmethods’, ‘add_custom_mautic_contactmethods_generic’ );

    /* A3. Save the fields during user registration (separated for POST and GET) */
    add_action(‘user_register’, ‘my_save_source_fields_to_user’, 10, 1);
    function my_save_source_fields_to_user($user_id) {
    $keys = array(‘affiliate_id’, ‘platform_source’, ‘platform_medium’);
    foreach ($keys as $key) {
    $value = ”;
    // First: Check for a POST value in the form_fields array
    if ( isset($_POST[‘form_fields’][$key]) && $_POST[‘form_fields’][$key] !== ” ) {
    $value = sanitize_text_field($_POST[‘form_fields’][$key]);
    }
    // Then: Check for a GET parameter (overwrites POST if present)
    if ( isset($_GET[$key]) && $_GET[$key] !== ” ) {
    $value = sanitize_text_field($_GET[$key]);
    }
    if ($value !== ”) {
    update_user_meta( $user_id, $key, $value );
    }
    }
    }

    /* B. Display in the user profile: Custom “Source Information” section */
    function my_show_source_user_profile( $user ) {
    $keys = array(‘affiliate_id’, ‘platform_source’, ‘platform_medium’);
    $labels = array(
    ‘affiliate_id’ => ‘Affiliate ID’,
    ‘platform_source’ => ‘Platform Source’,
    ‘platform_medium’ => ‘Platform Medium’
    );
    ?>

    ID, $key, true ); ?>
    <?php
    }
    add_action( ‘show_user_profile’, ‘my_show_source_user_profile’ );
    add_action( ‘edit_user_profile’, ‘my_show_source_user_profile’ );

    /* B2. Save the fields during profile update */
    function my_save_source_user_profile_fields( $user_id ) {
    if ( ! current_user_can( ‘edit_user’, $user_id ) ) {
    return false;
    }
    $keys = array(‘affiliate_id’, ‘platform_source’, ‘platform_medium’);
    foreach ( $keys as $key ) {
    if ( isset( $_POST[$key] ) ) {
    update_user_meta( $user_id, $key, sanitize_text_field( $_POST[$key] ) );
    }
    }
    }
    add_action( ‘personal_options_update’, ‘my_save_source_user_profile_fields’ );
    add_action( ‘edit_user_profile_update’, ‘my_save_source_user_profile_fields’ );

    /* C. Fill form fields via URL on the frontend (JavaScript)
    Note: Your registration form must include fields with the names:
    form_fields[affiliate_id], form_fields[platform_source], and form_fields[platform_medium]
    ideally as hidden fields.
    */
    add_action(‘wp_footer’, ‘my_fill_fields_from_url’);
    function my_fill_fields_from_url() {
    $keys = array(‘affiliate_id’, ‘platform_source’, ‘platform_medium’);
    $js = “”;
    echo $js;
    }

    /* D. Lead Conversion to WP-Slice:
    Immediately after registration, if an affiliate_id exists,
    convert the visitor into a lead in WP-Slice by calling slicewp_insert_lead().
    Only the essential parameters are passed, including a valid timestamp (formatted as “Y-m-d H:i” without seconds),
    the user’s email, and the original URL in the “entry” field.
    */
    function my_convert_visitor_to_lead( $user_id ) {
    // Retrieve affiliate_id from user meta
    $affiliate_id = get_user_meta( $user_id, ‘affiliate_id’, true );
    if ( empty( $affiliate_id ) ) {
    error_log(“User $user_id has no affiliate_id – skipping lead conversion.”);
    return;
    }

    // Create a timestamp using current_time('mysql') and trim seconds (format: Y-m-d H:i)
    $mysql_date = current_time('mysql'); // e.g., "2025-02-23 14:35:42"
    $created_at = substr($mysql_date, 0, 16); // "2025-02-23 14:35"
    
    // Get the user's email from their data
    $user_data = get_userdata( $user_id );
    $email = $user_data ? $user_data->user_email : '';
    
    // Get the original URL (if needed)
    $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http";
    $original_url = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    
    // Prepare lead parameters with minimal required data
    $lead_data = array(
        'affiliate_id' => $affiliate_id,
        'user_id'      => $user_id,
        'email'        => $email,
        'description'  => 'Lead generated from registration form',
        'type'         => 'lead',
        'created_at'   => $created_at,
        'entry'        => $original_url
    );
    
    if ( function_exists( 'slicewp_insert_lead' ) ) {
        $lead_id = slicewp_insert_lead( $lead_data );
        error_log("WP-Slice: Lead (ID: $lead_id) for user $user_id created (via slicewp_insert_lead) with date: $created_at, email: $email, and entry: $original_url.");
    } else {
        error_log("WP-Slice: Function slicewp_insert_lead() not found.");
    }

    }
    add_action( ‘user_register’, ‘my_convert_visitor_to_lead’, 35, 1 );

    Plugin Author iova.mihai

    (@iovamihai)

    Hey @growsmartehg,

    From what I see, your $lead_data array do not contain the correct elements, thus the issues you’re seeing.

    I recommend searching our plugin’s code to see how we’re inserting leads. This will give you a clearer image of the data array you need to pass to the insert function.

    Here’s a quick example though:

    // Prepare lead data.
    $lead_data = array(
    'affiliate_id' => absint( $affiliate_id ),
    'visit_id' => ( ! is_null( $visit_id ) ? absint( $visit_id ) : 0 ),
    'origin' => 'your_origin',
    'form_id' => absint( $form_submit->form_id ),
    'entry_id' => absint( $form_submit->id ),
    'date_created' => slicewp_mysql_gmdate(),
    'date_modified' => slicewp_mysql_gmdate(),
    'email' => $lead_email_address,
    'first_name' => $lead_first_name,
    'last_name' => $lead_last_name
    );

    // Insert the lead.
    $lead_id = slicewp_insert_lead( $lead_data );

    Also, for the dates you can use SliceWP’s slicewp_mysql_gmdate() function, as it will format the current time as needed in the database.

    Thank you and best wishes,

    Mihai

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom Form’ is closed to new replies.