Okay
  Public Ticket #3578969
Earnings record is duplicated. Duplicate cannot be deleted. Even when agent is changed, the duplicate for the previous agent does not go away.
Closed

Comments

  • Virginia started the conversation

    Earnings record is duplicated.  Duplicate cannot be deleted. Even when agent is changed, the duplicate for the previous agent does not go away.

  •  1,893
    WebWizards replied

    Hi Virginia,

    Thank you for purchasing our plugin,


    (1) I am not completely sure if I understood the issue correctly, but does that mean the same order generates earnings twice?

    It would help if you can share a screenshot.

    Certainly, that should not happen, and an order should only generate earnings once. Perhaps however there is a misconfiguration or some kind of conflict.

    If you'd like, we can check this directly on your site and troubleshoot the issue. For that, we would need a backend login to the site, or to a staging clone site.


    (2)

    Regarding changing an agent, please note it is normal that this area does not change commissions:

    4662886623.png

    This area only controls who can edit / manage the order.


    If you want to edit commissions for an order, please scroll down to the bottom of the edit order page and edit commissions via the panel here:

    8060954500.png

    To delete a commission here, please click on the pencil icon and then enter 0:

    3445252855.png

    Then after saving the order, the commission is deleted.


    Looking forward to your response,

    Kind regards,

    Stefan

  •   Virginia replied privately
  •  1,893
    WebWizards replied

    Hi Virginia,

    Thank you for the detailed reply,


    I believe most likely the issue was related to a previous plugin bug which is now resolved.


    To correct the issue for that specific order, please try the following:

    1. Set the order status to 'processing'

    2. Add this code snippet to your site:

    add_action('plugins_loaded', function(){
        // also get all earnings where this agent is parent
        $earnings = get_posts( array( 
            'post_type' => 'salesking_earning',
            'numberposts' => -1,
            'post_status'    => 'any',
            'fields'    => 'ids',
            'meta_key'   => 'order_id',
            'meta_value' => '5321',
        ));
        foreach ($earnings as $earning_id){
            wp_delete_post($earning_id);
        }
    });
    

    https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/

    Run the snippet only once, so that the earnings are deleted.

    3. Remove the code snippet.

    4. Then go to the order page and add the commission manually

    5. Set the status back to completed.


    Hopefully that should correct it for this specific order and the issue should not return.


    Let me know if that can solve it for you,


    Kind regards,

    Stefan

  •   Virginia replied privately
  •  1,893
    WebWizards replied

    Hi Virginia,

    I looked further into that and it seems the hook I used did not work as a snippet there.


    Please try those steps again exactly as previously, but with the following code:

    add_action('admin_init', function(){
        // also get all earnings where this agent is parent
        $earnings = get_posts( array( 
            'post_type' => 'salesking_earning',
            'numberposts' => -1,
            'post_status'    => 'any',
            'fields'    => 'ids',
            'meta_key'   => 'order_id',
            'meta_value' => '5321',
        ));
        foreach ($earnings as $earning_id){
            wp_delete_post($earning_id);
        }
        delete_post_meta(5321,'salesking_earning_id', '');
    });
    

    I tested this code locally with that code snippets plugin, set to "execute once" and it seems to work in my tests. If for some reason this does not work for you, could you please share a backend access to the site or staging site, so we can work on it directly?


    Kind regards,

    Stefan