• Resolved hs

    (@haradhansharma)


    /// custom code for wpam
    function delete_wpam_commission_if_again_rewarding($txn_id) {
    global $wpdb;
    $table = WPAM_TRANSACTIONS_TBL;
    $query = "
    SELECT *
    FROM ".WPAM_TRANSACTIONS_TBL."
    WHERE referenceId = %s
    AND amount < 0
    AND type = 'refund'
    ";
    $txn_record = $wpdb->get_row($wpdb->prepare($query, $txn_id));
    WPAM_Logger::log_debug('Commission record deleted for PURCHASE LOG ID: '.$txn_record->referenceId);
    if($txn_record != null) { //found a refunded commission record
    WPAM_Logger::log_debug('Deleting commission record for PURCHASE LOG ID: '.$txn_id);

    // Delete the commission record
    $wpdb->delete(
    $table,
    array('referenceId' => $txn_id, 'type' => 'refund'),
    array('%d', '%s')
    );

    WPAM_Logger::log_debug('Commission record deleted for PURCHASE LOG ID: '.$txn_id);
    } else {
    WPAM_Logger::log_debug('No commission record found for PURCHASE LOG ID: '.$txn_id.'. Nothing to delete.');
    }
    }


    add_action('init', function() {
    global $wpam_plugin;
    if (isset($wpam_plugin)) {
    remove_action('woocommerce_order_status_processing', [$wpam_plugin, 'WooCommerceProcessTransaction']);
    remove_action('woocommerce_checkout_order_processed', [$wpam_plugin, 'WooCommerceProcessTransaction']);
    remove_action('woocommerce_order_status_completed', [$wpam_plugin, 'WooCommerceProcessTransaction']);

    // while rewarding commission after return happened earlier due to operation error then refund will delete to ensure correct account
    add_action('woocommerce_order_status_completed', 'modified_wpam_process_transaction');

    // if by mistake marked as completed then to return it to proccessing or hold again then will give below flexibility
    add_action('woocommerce_order_status_processing', [$wpam_plugin, 'WooCommerceRefundTransaction']);
    add_action('woocommerce_order_status_on-hold', [$wpam_plugin, 'WooCommerceRefundTransaction']);
    }
    });

    function modified_wpam_process_transaction($order_id) {
    global $wpam_plugin;
    if (!isset($wpam_plugin)) {
    return;
    }

    // First, remove any existing refund if rewarding happening after refund done
    delete_wpam_commission_if_again_rewarding($order_id);

    // Now process the commission
    $wpam_plugin->WooCommerceProcessTransaction($order_id);

    WPAM_Logger::log_debug("Order ID: $order_id processed with commission deletion check.");
    }
    /// custom code for wpam
Viewing 1 replies (of 1 total)
  • Plugin Support mbrsolution

    (@mbrsolution)

    Thank you very much for sharing your custom code. I have submitted a message to the developers to investigate further your code.

    Kind regards.

Viewing 1 replies (of 1 total)

The topic ‘this flexibility can be added’ is closed to new replies.