Add the referred affiliate number to the affiliate account page.
-
Hi @iovamihai,
I guess I need to open a new topic, so here it is. Can I add the code you provided to the dashboard of affiliate user account page so that user will know how many affiliates he has already referred when he logged in?
Sorry for asking too many requests ??
-
Hey @kuschang,
This one if a bit more difficult to implement, but I have managed to do it with some workarounds.
Here’s the code:
function slicewp_custom_affiliate_account_tab_dashboard_referred_affiliates_cards() { $current_date_min = ( new DateTime() )->sub( new DateInterval( 'P29D' ) ); $current_date_min->setTime( 00, 00, 00 ); $current_date_max = new DateTime(); $current_date_max->setTime( 23, 59, 59 ); $affiliate_id = slicewp_get_current_affiliate_id(); $children_count_last_30_days = slicewp_get_affiliates( array( 'parent_id' => $affiliate_id, 'date_min' => get_gmt_from_date( $current_date_min->format( 'Y-m-d H:i:s' ) ), 'date_max' => get_gmt_from_date( $current_date_max->format( 'Y-m-d H:i:s' ) ) ), true ); $children_count_all = slicewp_get_affiliates( array( 'parent_id' => $affiliate_id ), true ); ?> <div class="slicewp-card slicewp-card-affiliate-dashboard slicewp-card-affiliate-dashboard-referred-affiliates-last-30-days"> <div class="slicewp-card-inner"> <div class="slicewp-card-title">Referred Affiliates</div> <div class="slicewp-kpi-value"><?php echo absint( $children_count_last_30_days ); ?></div> </div> </div> <div class="slicewp-card slicewp-card-affiliate-dashboard slicewp-card-affiliate-dashboard-referred-affiliates-all-time"> <div class="slicewp-card-inner"> <div class="slicewp-card-title">Referred Affiliates</div> <div class="slicewp-kpi-value"><?php echo absint( $children_count_all ); ?></div> </div> </div> <script> document.querySelector('.slicewp-grid-affiliate-dashboard-last-30-days').appendChild( document.querySelector( '.slicewp-card-affiliate-dashboard-referred-affiliates-last-30-days' ) ); document.querySelector('.slicewp-grid-affiliate-dashboard-all-time').appendChild( document.querySelector( '.slicewp-card-affiliate-dashboard-referred-affiliates-all-time' ) ); </script> <style> .slicewp-grid.slicewp-grid-affiliate-dashboard-last-30-days { grid-template-columns: repeat( auto-fit, minmax( 20%, 1fr ) ); } .slicewp-grid.slicewp-grid-affiliate-dashboard-all-time { grid-template-columns: repeat( 5, minmax( 0, 1fr ) ) } </style> <?php } add_action( 'slicewp_affiliate_account_tab_dashboard_bottom', 'slicewp_custom_affiliate_account_tab_dashboard_referred_affiliates_cards' );
The code will add two new boxes in the affiliate’s dashboard, named “Referred Affiliates”. One box will be added to the “Last 30 days” section and one to the “All time” section of the dashboard.
Please add the code and let me know how it goes.
Thank you and best wishes,
Mihai
Hi @iovamihai
Actually I have added some codes from chatgpt created for me yesterday ?? in the affiliate dashboard tab template.
$args = array( 'number' => -1, 'fields' => 'user_id', 'parent_id' => $args['affiliate_id'] ); $referred_affiliates = slicewp_get_affiliates( $args ); and this: <div class="slicewp-card slicewp-card-affiliate-dashboard"> <div class="slicewp-card-inner"> <div class="slicewp-card-title"><?php echo __( 'Referrals', 'slicewp' ); ?></div> <div class="slicewp-kpi-value"><?php echo count($referred_affiliates); ?> org</div> </div> </div>
It worked, but yours are way better. So I’m gonna use your provided code.
I have also added the “converted” column in the affiliate visit tab template (from chatgpt) maybe not beautiful but it worked.
I added this: <th><?php echo __( 'Converted', 'slicewp' ); ?></th> and this: <td> <?php if ( empty( $visit->get('commission_id') ) ) : ?> <span class="slicewp-status-icon"><?php echo slicewp_get_svg( 'outline-x' ); ?> No</span> <?php else : ?> <span class="slicewp-status-icon slicewp-status-converted"><?php echo slicewp_get_svg( 'outline-check' ); ?> Yes</span> <?php endif; ?> </td>
Would it be a problem with the code in the future?
Anyway, thanks a lot for the help Mihai.
Hey @kuschang,
Modifying the plugin’s template is not recommended because of plugin updates. When you update the plugin all files are overwritten, so if you change any file, the changes will disappear.
You can have a copy of the template file on your computer and after you update the plugin, you replace the template file. However, you’d have to do this after each plugin update, which is not the best solution.
The optimal way would be for you to create a child theme (if you don’t already have one) and within that theme to create a new folder named “slicewp”. Within this folder you can copy the template file and modify it as you please. This way, the plugin will look for the template file from the child theme first. In this scenario, updating the plugin will have no effect on the template file that you have in your child theme.
I know this is a bit more complicated, but it’s the safest solution in the long run.
Thank you and best wishes,
Mihai
Yes, I have put all the template files into themes/child-theme/slicewp/affiliate-area.
I finally get the workaround of creating a new column inside affiliate-account-tab-commissions template and shows the referred affiliate name for each row.
<td><?php $order_id = $commission->get('reference'); $order = wc_get_order( $order_id ); $customer_name = $order->get_billing_first_name(); echo $customer_name; ?> </td>
Let me know what you think.
Thank you very much @iovamihai really appreciate all your help.
Rikiez
Hey @kuschang,
The code looks good! Also, considering that you put all the template files in the child theme you should be good to go. Plugin updates will not affect your template changes.
Best wishes,
Mihai
- The topic ‘Add the referred affiliate number to the affiliate account page.’ is closed to new replies.