Skip Navigation

[Resolved] Refund on site when partial credits have been used

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 9 replies, has 2 voices.

Last updated by Nigel 6 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#606145

I am trying to: issue a refund for a customer. They have 5 ad credits, but have used 1. For whatever reason in our simulation we have decided to give them a refund. The refund itself worked perfectly: hidden link

Link to a page where the issue can be seen:
However the user still sees ad credits here: hidden link

If they check their listing packages, there are no active packages, which is correct. (see hidden link)

I expect to see the ad credits to be 0, but instead they are 4. Does that mean that the shortcode [classifieds-return-available-ad-credits] can only have the full package amount deducted, instead of the remaining amount on the package?

Thanks!

#606159

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Stephanie

I don't recognise your screenshots, and the [classifieds-return-available-ad-credits] shortcode is not a Toolset shortcode, certainly not one I recognise and it doesn't appear to be registered by our classifieds site, for example.

Can you tell me more about your site and how it is made?

#606161

Hi - this is a variable based on the Classifieds reference site and is referred to here: https://toolset.com/forums/topic/classified-shortcodes/

Are you familiar with the Classifieds reference site (see: https://toolset.com/reference-site/toolset-classifieds/)

Our version of the site turns the above Toolset reference site from strictly classifieds to property listing. I have not changed any of the packages (except for the labels, which shouldn't affect anything). All the functionality is something that comes with the reference site.

#606188

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Stephanie

Sorry about that, I did a search on the plugin that registers the custom classifieds shortcodes to see if it was one of ours but I had a typo in my search term.

The shortcode [classifieds-return-available-ad-credits] simply outputs the number of credits for a user.

I looked through the code that handles the logic of buying ad packages and assigning credits, and there is no provision for handling refunds.

You'll need to add some code to handle this yourself.

The available credits are stored as custom user meta with a key of wpcf-user-total-available-ad-credits.

You can use a WooCommerce hook such as woocommerce_order_refunded (https://docs.woocommerce.com/wc-apidocs/source-function-wc_create_refund.html#594) to trigger some custom code that deducts credits from the stored total.

Although the reference sites are provided for training and as proof-of-concepts rather than fully-fledged solutions it would be helpful if such functionality were built-in, and I'm passing that feedback on to Agnes who is responsible for the reference sites.

#606203

Nigel,

I'll follow your link and take a look.

Good call on passing back that feedback as your Reference Sites page says "Toolset Reference Sites are fully functional website designs that you can use as the starting point for your own website. Each of these reference sites represents a project with a specific purpose." I imagine I'm not the first. 🙂

Will this ticket remain open should I have any further questions?

Regards,
Stephanie

#606205

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Yes, Stephanie

Leave this open while you implement that and if you can't get it to work let me know and I'll try to help.

#609415

OK - I've had a look through, and while I can do some custom stuff, I have two questions first.

Question 1:
With regards to the credits under the packages type... there seems to be some deduction as ads are consumed. See:
hidden link
Does this affect any text on the site? If you change this value alone it doesn't seem to affect anything (hence, the point)?

Question 2:
On the My Account dashboard there is some text here: hidden link
What drives this value? (Apologies if it's obvious - I feel like I'm following loops til I'm cross-eyed here)

Thanks!
S.

#609693

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-01-25 at 11.15.23.png
Screen Shot 2018-01-25 at 11.16.13.png

Hi Stephanie

I think those questions are the same thing, no?

Look at my two screenshots, both created after I had published one of my five available ads.

#609800

Hi Nigel - thanks for sticking with me on this one.

With point 1 - If I manually change the "Package number of ads allowed" to zero, then it is not reflected on the screen hidden link

With point 2 - I'm asking because on the Woocommerce page it seems to be added as well.
See the following link after I buy a package:
hidden link
I've had a request if it can be removed from this page.

Regards,
Stephanie

#610094

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Stephanie

On the My Account screen shown in your screenshot, that section is generated by the "My Account sidebar" Content Template.

If you examine that you'll see the number of available ads is generated with the classifieds-return-available-ad-credits shortcode.

If you examine the code in the toolset-classifieds plugin you'll see that the shortcode uses the following function:

        /*Function to compute available ad credits*/
        public function classifieds_return_available_ad_credits($user_id = '') {
            if (empty($user_id)) {
                global $current_user;
                //Get user_id
                $user_id = $current_user->ID;
            }
            //Get number of ad package credits for this user
            $ad_credits_available = get_user_meta($user_id, 'wpcf-user-total-available-ad-credits', TRUE);

            $out = '0';
            if ($ad_credits_available){
                $out = $ad_credits_available;
            }

            return $out;

        }

Note that it retrieves the number of available ads from USER meta.

When you are looking at the package in the WordPress admin, that is a post, and so the number of ad packages there is POST meta. If you change that, you are not changing the USER meta where the number of available ads is stored. (Looking in the same file there is a function which displays the same USER meta on the WooCommerce page.)

If you look in the file package_order.class.php you'll see a function classifieds_cred_submit_complete_add_another_premium_ad on line 43.

If you read through that you'll notice that when an ad is submitted it updates both the user meta and post meta.

If you are adjusting the number of available ads you'll need to do the same.

I hope that helps.