Display “N/A” when referrals totals is null

Hi guys,

What would be the best way to achieve this?

I can see that there seems to be a filter here available “affiliates_referrals_display_total_none”, however I was unable to find where this filter is added.

$output .= apply_filters( 'affiliates_referrals_display_total_none', wp_filter_nohtml_kses( $if_empty ) );

When this line returns en empty string I would like to use “N/A”. Currently it just displays nothing, which makes it look like something wrong is going on.

Do I have to create a function like that :

add_filter( 'affiliates_referrals_display_total_none', 'nh_affiliate_zero_total' );
function nh_affiliate_zero_total( $nhtotal ) {
// Check if empty?
return $nhtotal;
}

If yes, how would I check if the total is empty?

If there’s a simpler way, what would it be?

Thanks!

Kind regards,
B

15 Responses to Display “N/A” when referrals totals is null

  1. George February 13, 2016 at 10:07 am #

    Hi Bastien,

    Although you are free to modify plugin’s files, it is not suggested because that way you will lose your modifications after a future update. That’s the reason after all that WP uses hooks and that i suggested you to write a new shortcode. 🙂 Also, since this modification applies to your use case only, at least for the moment, i honestly don’t know when and if it can be added in the core functionality.

    You can have a look at the Shortcode API or simply follow the process of my custom Affiliate Referrer shortcode.
    No matter the case, you can reply here for assistance.

    Kind regards,
    George

  2. Bastien February 11, 2016 at 9:23 pm #

    Note (all false statement are empty, they should display the ul and li tags)

  3. Bastien February 11, 2016 at 9:23 pm #

    George,

    One last thing, I modified the shortcode to allow users to get rid of the ul and li tags surrounding the total. Would you mind reviewing the modifications and adding them to a future version if it makes sense?

    File class-affiliates-shortcodes.php

    -Added the “no_table” attribute

    $options = shortcode_atts(
    array(
    'status' => null,
    'from' => null,
    'until' => null,
    'show' => 'count',
    'currency' => null,
    'for' => null,
    'if_empty' => null,
    'no_table' => null
    ),
    $atts
    );
    ex

    -Wrapped the li and ul tags to be dependant on the no_table variable

    case 'total' :
    if ( $totals = self::get_total( $affiliate_id, $from, $until, $status ) ) {
    if ( count( $totals ) > 0 ) {
    $output .= $no_table ? '' : '';
    foreach ( $totals as $currency_id => $total ) {
    $output .= $no_table ? '' : '';
    $output .= apply_filters( 'affiliates_referrals_display_currency', $currency_id );
    $output .= ' ';
    $output .= apply_filters( 'affiliates_referrals_display_total', number_format_i18n( $total, apply_filters( 'affiliates_referrals_decimals', 2 ) ), $total, $currency_id );
    $output .= $no_table ? '' : '';
    }
    $output .= $no_table ? '' : '';
    }
    }
    if ( !$totals || count( $totals ) === 0 ) {
    if ( $if_empty !== null ) {
    $output .= $no_table ? '' : '';
    $output .= $no_table ? '' : '';
    $output .= apply_filters( 'affiliates_referrals_display_total_none', wp_filter_nohtml_kses( $if_empty ) );
    $output .= $no_table ? '' : '';
    $output .= $no_table ? '' : '';
    }
    }

    Thank you!

    Regards,
    B

  4. Bastien February 11, 2016 at 9:02 pm #

    Hello George,

    I feel a bit stupid. I had modified the file class-affiliates-shortcodes.php and never kept the original as I usually do. When I put back the original file it started working, although I have slightly modified the previous function :

    // =============================================================================
    // Affiliates Enterprise - Display N/A when total is zero
    // =============================================================================
    add_filter( 'affiliates_referrals_display_total_none', 'nh_affiliate_zero_total', 10, 1 );
    function nh_affiliate_zero_total($if_empty) {
    if ($if_empty) {
    $message = "N/AAAAA";
    return $message;
    }
    }

    Thank you for the help!

    Kind regards,
    B

  5. George February 11, 2016 at 10:32 am #

    Hi Bastien,

    Then you should rewrite the shortcode and modify the output to cover the case when there is amount but it is zero. I’m also preparing something so that you can use/compare it to yours.

    Cheers

  6. Bastien February 8, 2016 at 11:10 pm #

    Hey George,

    I added the parameter if_empty=”true” and the shortcode started to display “1” instead of nothing which is a good start hehe.

    I then added the following filter but it seems it’s not working.


    // =============================================================================
    // Affiliates Enterprise - Display N/A when total is zero
    // =============================================================================
    add_filter( 'affiliates_referrals_display_total_none', 'nh_affiliate_zero_total' );
    function nh_affiliate_zero_total() {
    $message = "N/A";
    return $message;
    }

    Am I missing something again?

    Thank you for your help and patience!

    Kind regards,
    B

  7. George February 8, 2016 at 8:09 pm #

    Hi Bastien,

    Both these shortcodes render html so you might even have to make your own shortcode, meaning a copy of the existing shortcode and simply modify the name of it and the output when there is no total.

    First, try using the filter affiliates_referrals_display_total_none to modify the output message if there is no total. The snippet to add should be the same like the previous one you used. Also, for this to render properly, you should also add the attribute if_empty=”true” in the shortcode [affiliates_referrals]. i.e. [affiliates_referrals show="totals" if_empty="true"].

    Hope this is more helpful.

    Cheers

  8. Bastien February 8, 2016 at 2:35 pm #

    Hello George,

    Since [affiliates_earnings] renders a table and that we need just the raw value without HTML [affiliates_referrals] is the best fit for us as we can create our “Pending payment” indicator for the current month (without history or anything, just the current pending payment amount).

    As soon as a referral is validated for the set period (for=”month” in our case), a value will be displayed by the shortcode. For example, after an user was permanently assigned to my affiliate account, it started displaying “CAD 0,00” (we don’t give anything for a registration but a referral was added). Before that referral the shortcode wouldn’t render anything.

    Would it be possible to use a filter to replace the output if it’s null or equal to zero?

    Thank you!

    Kind regards,
    B

  9. George February 8, 2016 at 9:08 am #

    Hi Bastien,

    It doesn’t render anything, or the table is empty?

    Cheers

  10. Bastien February 5, 2016 at 3:03 pm #

    Hey George,

    Mmm well then I guess [affiliates_referrals] is the shortcode I’m looking for but when there are no referrals for the current affiliate this shortcode displays nothing. How would I add a message instead?

    Thank you.

    Kind regards.
    B

  11. George February 5, 2016 at 1:05 pm #

    Hi Bastien,

    The shortcode doesn’t accept any parameters. The shortcode renders a table containing one row per month, starting from when historic referral data is available for the affiliate, up to the current date.

    Cheers.

  12. Bastien February 4, 2016 at 11:36 pm #

    Hello George,

    Should have seen that. Thank you for the information.

    In the shortcode documentation (http://docs.itthinx.com/document/affiliates/shortcodes/affiliates_earnings/) it seems there are no parameter we can set, is that correct?

    If there are no parameters, how would I display only the total earnings for the current month using [affiliates_earnings] without any table?

    Kind regards,
    B

  13. George February 4, 2016 at 3:21 pm #

    Hi Bastien,

    Try using [affiliates_earnings] shortcode, as the name of the filter indicates.

    Cheers

  14. Bastien February 3, 2016 at 4:36 pm #

    Hello George,

    Thank you for this information. I have added the following function to our child-theme functions.php but it doesn’t seems to do anything :

    // =============================================================================
    // Affiliates Enterprise - Display N/A when total is zero
    // =============================================================================
    add_filter( 'affiliates_earnings_display_total_no_earnings', 'nh_affiliate_zero_total' );
    function nh_affiliate_zero_total( $message ) {
    $message = "N/A";
    return $message;
    }

    Am I missing something? Here’s the shortcode we use on the affiliate dashboard :

    [affiliates_referrals for="month" status="accepted" show="total"]

    In the filters documentation (http://docs.itthinx.com/document/affiliates/api/filters/) I see that the default message returned should be ‘There are no earnings yet.’. How come I’m not seeing this?

    Kind regards,
    B

  15. George February 3, 2016 at 2:10 pm #

    Hi Bastien,

    You can use affiliates_earnings_display_total_no_earnings to modify the message that is displayed.
    Accepted parameter is $message and as return value you should return your desired message.

    Kind regards,
    George

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share