• Resolved scottjonesk

    (@scottjonesk)


    Hello,
    I am in need of exporting AffiliateWP referral names along with the export of order information. Is there a code to create this field?

    Thank you,

    Scott

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    Please, follow to https://docs.algolplus.com/algol_order_export/fields/
    add field affiliate_id
    use this code

    add_filter( "woe_fetch_order", function($row, $order ){
    global $wpdb;
    $user_id = $wpdb->get_var( "SELECT aff.user_id
    FROM {$wpdb->prefix}affiliate_wp_referrals AS ref
    LEFT JOIN {$wpdb->prefix}affiliate_wp_affiliates AS aff
    ON aff.affiliate_id = ref.affiliate_id
    WHERE ref.context='woocommerce' AND ref.reference=".$order->get_id() );
    if($user_id) {
    $user_info = get_userdata($user_id);
    $row["affiliate_id"]= $user_info->user_email;
    }
    return $row;
    },10,2);

    Thread Starter scottjonesk

    (@scottjonesk)

    Thank you. This is great. I created a meta key affilitate_id under Products and then tried Common. Both gave me this error. I think we’re almost there. Please help? Thank you!

    Uncaught Error: Call to undefined function ​add_filter() in /home3/mhurefmy/public_html/wp-content/plugins/woo-order-export-lite/classes/core/class-wc-order-export-engine.php(369) : eval()’d code:1 Stack trace: #0 /home3/mhurefmy/public_html/wp-content/plugins/woo-order-export-lite/classes/core/class-wc-order-export-engine.php(369): eval() #1 /home3/mhurefmy/public_html/wp-content/plugins/woo-order-export-lite/classes/core/class-wc-order-export-engine.php(431): WC_Order_Export_Engine::validate_defaults(Array) #2 /home3/mhurefmy/public_html/wp-content/plugins/woo-order-export-lite/classes/admin/tabs/ajax/trait-wc-order-export-admin-tab-abstract-ajax-export.php(22): WC_Order_Export_Engine::build_file(Array, ‘estimate_previe…’, ‘file’, 0, 0, ‘test’) #3 /home3/mhurefmy/public_html/wp-content/plugins/woo-order-export-lite/classes/class-wc-order-export-admin.php(531): WC_Order_Export_Admin_Tab_Abstract->ajax_preview() #4 /home3/mhurefmy/public_html/wp-includes/class-wp-hook.php(310): WC_Order_Export_Admin->ajax_gate(”) #5 /home3/mhurefmy/public_html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(”, Array) #6 /home3/mhurefmy/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #7 /home3/mhurefmy/public_html/wp-admin/admin-ajax.php(188): do_action(‘wp_ajax_order_e…’) #8 {main} thrown

    Plugin Author algol.plus

    (@algolplus)

    please, visit https://onlinephp.io/ and paste your code .

    I think you copied some non-printable chars

    Thread Starter scottjonesk

    (@scottjonesk)

    Thank you,

    it quoted back

    Fatal error: Uncaught Error: Call to undefined function ​add_filter() in /home/user/scripts/code.php:2
    Stack trace: 0 {main}

    thrown in /home/user/scripts/code.php on line 2

    The code I used, once again was

    add_filter( "woe_fetch_order", function($row, $order ){
    global $wpdb;
    $user_id = $wpdb->get_var( "SELECT aff.user_id
    FROM {$wpdb->prefix}affiliate_wp_referrals AS ref
    LEFT JOIN {$wpdb->prefix}affiliate_wp_affiliates AS aff
    ON aff.affiliate_id = ref.affiliate_id
    WHERE ref.context='woocommerce' AND ref.reference=".$order->get_id() );
    if($user_id) {
    $user_info = get_userdata($user_id);
    $row["affiliate_id"]= $user_info->user_email;
    }
    return $row;
    },10,2);

    Plugin Author algol.plus

    (@algolplus)

    please, put php code back to “Misc Settings”.
    I suggested to use https://onlinephp.io/  – only to check if you copied php code correctly from WordPress forum.

    • This reply was modified 2 years, 8 months ago by algol.plus.
    Thread Starter scottjonesk

    (@scottjonesk)

    Ok. Thank you. So onlinephp.io caught the error. Misc Settings has the entire code. Error is still the same. Sorry. What should I do next? I really appreciate the help!

    Thread Starter scottjonesk

    (@scottjonesk)

    Maybe I put the affiliate_id into the wrong spot? Which category? or does it matter? I see common, customer, billing address, shipping address, products, product order items, product totals, coupons, other items, cart, shipping, totals, and Others.

    Plugin Author algol.plus

    (@algolplus)

    Please, submit your settings as new ticket https://algolplus.freshdesk.com/

    Use >WooCommerce>Export Orders>Tools to get them.

    Thread Starter scottjonesk

    (@scottjonesk)

    Submitted as a ticket. Thank you!

    Thread Starter scottjonesk

    (@scottjonesk)

    Getting there! Thank you so much for the help!
    So I delete this first row of:
    add_filter( “woe_fetch_order”, function($row, $order ){

    then i get an error of

    The code you are trying to save produced a fatal error on line 11:Unmatched ‘}’

    add_filter( “woe_fetch_order”, function($row, $order ){
    global $wpdb;
    $user_id = $wpdb->get_var( “SELECT aff.user_id
    FROM {$wpdb->prefix}affiliate_wp_referrals AS ref
    LEFT JOIN {$wpdb->prefix}affiliate_wp_affiliates AS aff
    ON aff.affiliate_id = ref.affiliate_id
    WHERE ref.context=’woocommerce’ AND ref.reference=”.$order->get_id() );
    if($user_id) {
    $user_info = get_userdata($user_id);
    $row[“affiliate_id”]= $user_info->user_email;
    }
    return $row;
    },10,2);

    Plugin Author algol.plus

    (@algolplus)

    hi @scottjonesk

    please, look at screensot carefully https://snipboard.io/tVCf36.jpg
    I see bad char at begin of line //

    Don’t delete
    add_filter( “woe_fetch_order”, function($row, $order ){

    Thread Starter scottjonesk

    (@scottjonesk)

    Thank you. I am sure we’re going to get this. Could you give new code from scratch? Correct code in its entirety?
    Also, specifically where is affiliate_id to be created?

    Thank you!

    Plugin Author algol.plus

    (@algolplus)

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

The topic ‘AffiliateWP’ is closed to new replies.