jdh1178

Forum Replies Created

Viewing 25 posts - 1 through 25 (of 43 total)
in reply to: Private Create Pay link #186025

jdh1178
Participant

That’s great, thanks. Adding multiple items is working, thanks. Looking forward to the updates to custom order, cheers


jdh1178
Participant

Thanks

in reply to: Private Create Pay link #185924

jdh1178
Participant

I understand, thanks. I think the main issue is that ‘create order’ in admin doesn’t allow for modifications to item count (or price) and I was looking for some change to PayLink to circumvent that.

Example:
Store owner wants to setup a private, non-front end payment, for someone (as often is the case with corporate buyers who want to pay by bank transfer or card – for a variety of complex orders – imagine a school looking to purchase for different campuses) and receive some sort of discount based on bulk.

I’d thought to perhaps use Paylink to collect payment and then create the orders for them, but it’s not ideal as there is no solid way to fulfill the request by creating an order for the user once payment received (as they’re public) and because there is no way to fulfill the order currently by using Create New in order admin which has some limitations as to what can be created/edited.

Alternatively, I can create coupons for the user, but then they need to build the order/orders themselves and enter multiple coupons for each product (also not ideal).

I suppose the issue would be addressed by simply improving the admin ‘order create new’ functionality to allow for customizations with feature parity with the normal cart so that quantity, coupons, price can be configured by store admin rather than updating the Paylink functionality.

This way the store admin can setup an order easily for user and activate it once payment received by Paylink.

Alternatively, one can setup license pricing for each product that has tiers for quantity and just modify the code so that the license priced products are only available in the admin.


jdh1178
Participant

Awesome, thanks


jdh1178
Participant

Sweet, thanks guys. Minor things, but will continue to report them. ๐Ÿ™‚


jdh1178
Participant

Hi Nayeem, I’m well thanks.

This is in admin Order page. No serious issues caused by it – was just some wp errors popping in admin up so I wanted to report – when adding an item back it resolves itself.

– Create an order with one item (create>new)
– Remove the item (trash icon)
– Results (use query monitor):

Warning	Undefined variable $order_total		
wp-content/plugins/wpdm-premium-packages/includes/menus/templates/orders/view-order.php:146
Plugin: wpdm-premium-packages
Warning	Undefined variable $role_discount		
wp-content/plugins/wpdm-premium-packages/includes/menus/templates/orders/view-order.php:386
Plugin: wpdm-premium-packages
in reply to: Hook for order updated #185620

jdh1178
Participant

Just an update on this – it seems not so straightforward as some things happen via ajax and some things happen via php.

The best solution I’ve come up with is a function to listen for ajaxComplete (code example below) which I can then use to fire additional actions in wp to handle order updates. I’d thought to do this with php with the wp_ajax_wpdmpp_async_request, but it’s difficult to fire anything after the ajax requests (priority has to be earlier or they don’t fire).

User would still need to catch the non ajax updates though as well, so it’s also not ideal.

Would be great if any event that updates an order (ajax or php) fired a universal action so that developer can keep order related data updated/synced. If you have some other suggestions do let me know. I’m probably doing this the hard way for no reason ๐Ÿ™‚ Thanks

(function($) {
    $(document).ready(function() {
        // Check if we are in the wpdm admin area
        var currentURL = window.location.href;
        var targetURL = '/wp-admin/edit.php?post_type=wpdmpro';

        if (currentURL.indexOf(targetURL) !== -1) {
            // Run the AJAX event handlers only on the target page
            $(document).ajaxComplete(function(event, jqXHR, ajaxOptions) {
                if (ajaxOptions.url === ajaxurl) {
                    doSomethingOnAjaxComplete(ajaxOptions, jqXHR);
                }
            });
        } else {
            return;
        }

        // Function to execute when the WordPress AJAX URL is being used for different WPDM actions
        function doSomethingOnAjaxComplete(ajaxOptions, jqXHR) {
            console.log("WordPress AJAX URL used:", ajaxOptions);

            // Get the request data
            var requestData = ajaxOptions.data;

            // Do something on wpdmpp_async_request;
            if (requestData.indexOf('action=wpdmpp_async_request') !== -1) {
                // The 'action' parameter is set to 'wpdmpp_async_request'
                console.log('wpdmpp_async_request action detected from');
                
                // Get the response data from the AJAX request
                var responseData = jqXHR.responseText;
                console.log("Response data:", responseData);

                // Perform a custom action after the response is received (error or not, doesn't matter)
		callMyCustomWPFunction();
            }

	    // Do something on wpdmpp_updateOrderExpiryDate;
            if (requestData.indexOf('action=wpdmpp_updateOrderExpiryDate') !== -1) {
                // The 'action' parameter is set to 'wpdmpp_updateOrderExpiryDate'
                console.log('wpdmpp_async_request action detected');
               
                // Get the response data from the AJAX request
                var responseData = jqXHR.responseText;
                console.log("Response data:", responseData);

                // Perform a custom action after the response is received (error or not, doesn't matter)
		callMyCustomWPFunction();
            }

            // Etc...Do more things on other wpdmpp js ajax actions
        }
    });
})(jQuery);
in reply to: Hook for order updated #185589

jdh1178
Participant

Or perhaps another way to handle it is use the ajax actions wp_ajax_wpdmpp_async_request and wp_ajax_wpdmpp_anync_exec? Any input appreciated, thanks.

in reply to: Hook for order updated #185588

jdh1178
Participant

@Shahjada – any chance similar hooks can be placed on the ajax calls as well (updateOS(), updatePS() etc.) as well?

Just realized that my update() hooks aren’t firing and performing what’s required when updating things via the admin. In other words, doing it via ajax vs doing it via php should all fire wpdmpp_update_order and wpdmpp_order_updated, otherwise having the filters/actions on update() alone will lead to inconsistent behaviors. There are a bunch of individual actions it seems in admin that ‘update’ the order to handle though.

Alternatively, I could prob solve this on my end by just adding a custom button to admin order edit page called ‘save all’ that fires to ensure nothing is missed for shop administrator, but a bit hacky and error prone solution.

Thanks


jdh1178
Participant

Ah, I see, duh…makes sense. Thanks, going to check if I should refactor or just let it be. ๐Ÿ™‚ Much appreciated!


jdh1178
Participant

Great thanks


jdh1178
Participant

Thanks, that seems to be working now without errors now.

One thing – before you replied I was looking at the dynamicItem which gave me some ideas on how to skip the addItem and add it by:
1. get_option( $cart_id, array() );
2. modify cart data
3. update_option( $cart_id, $cart_data, false );

This worked and allowed me to also update the cart item data freely (quantity, price etc.) which I needed to do anyways. Is there a method for updating the cart item that should be used or is get_option/update_option the way to do it?

The methods I found (updateItem, addDynamicItem etc.) are all limited in their scope as to what can be updated.

For example: I wanted to programmatically create an order with:
– item discount set to equal the price
– quantity and name based on arguments
– extra info to be used for tracking etc.

Seems that using get_option and update_option is still the only way to do this?

Thanks


jdh1178
Participant

Doh, my previous message got erased when editing it. I’ll try again:

I’m trying to follow your instructions to create an order, but getting undefined discount_amount when running open() and error points here.

When addItem(), there is no discount_amount, only role discount in the $cart_data and so when calling open() it fails here.

Fails here

Am I missing something? Thanks

in reply to: Hook for order updated #185363

jdh1178
Participant

Amazing, thank you very much!


jdh1178
Participant

Awesome, thanks as always!

in reply to: Customize membership pro templates #184980

jdh1178
Participant

I understand that, but there is no mention on your membership pro there. That’s why I’m asking. The views in Membership Pro aren’t in ‘views’ or ‘templates’ so was wondering what the procedure is, if any.

in reply to: Customize membership pro templates #184935

jdh1178
Participant

Hi Tanvir, I mean for files that are display oriented like in Account/my-account, user-account etc. Are they setup for overrides if I put them in a particular place or should I just manually configure things to use my own? Thanks


jdh1178
Participant

Thanks Tanvir. Makes sense. Will go with free then and just manage the active status. Good to know the multiple memberships for a single user isn’t a problem! Cheers


jdh1178
Participant

Sure, I’d simply like to display some custom data in the admin for an order. If we can’t modify the admin templates is there a hook for this? In this particular case, the new getOrder hook will work fine actually, so not really an issue anymore, but in general is there a preferred way to add meta to the order admin?


jdh1178
Participant

Just a follow-up:

I asked the new chat-gpt 4 (demo was released) for help and it suggested using debug_backtrace which I’ve never used before. Learned something new.

Not sure about implications though, but it works with getOrder filter now without interfering with the order details page, so I’m assuming it’s all good. The bot says it’s discouraged to use it in production, but by using ignore args shouldn’t be a performance issues and that it’s ‘safe’ to use with DEBUG_BACKTRACE_IGNORE_ARGS. Anyways, seems a bit overkill compared to just having a hook before the ‘error messages’ are displayed as it’s going to be running often, but it’s working so I can move on.

function wpdmpp_modify_order_data_temporarily_to_completed( $order_data ) {

    $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
    $is_download_func = false;

    // Check for calls to download()
    foreach ($trace as $call) {
        if (isset($call['function']) && $call['function'] === 'download') {
            $is_download_func = true;
            break;
        }
    }

    if ($is_download_func) {
        // Check order status, if expired, change to completed and set expire date to 10 seconds in the future
        if ($order_data->order_status == 'Expired') {
            $order_data->order_status = 'Completed';
            $order_data->expire_date  = time() + 10;
        }
    }

    return $order_data;
}

That said, is there some compelling reason not to simply add a hook at that specific location on odata? It might be useful for other cases as well so that user isn’t navigated to those error pages.

For example, store owner could also do things like :
– Issue an pay now/upgrade/renew upsell whenever download() runs and says ‘not allowed’ for whatever reason.
– ‘Your order expired on 3/23/23, so you can’t access things anymore. Upgrade your plan to access downloads? Yes, No. If no, then it continues to the error screen.

Thanks for your help, if you have some thoughts feel free. If you’re busy, no worries as it’s working this way for now and can mark resolved.


jdh1178
Participant

Thanks. No updates/support past a certain date, but continued access to the things you owned when you purchased. If updates are released and you want them, then you pay for them. But otherwise you can keep using what you owned. Always seemed fair to us. Plus we have 3rd party contractual obligations and technical restraints that make it literally impossible for us to deactivate anything anyways. If people lose/misplace their files, they should have a way to get them back imo, but future software releases are paid for. It’s a headache though! ๐Ÿ™‚

I’ve seen this model in the wp community as well (Delicious brains does this) where you can download what you owned up until the date of expiry. Seems fair.
delicious brains


jdh1178
Participant

Sorry I was typing and didn’t see your message. I’ve tried that:

add_filter( 'wpdmpp_get_order', 'wpdmpp_modify_order_data_temporarily_to_completed' );

function wpdmpp_modify_order_data_temporarily_to_completed( $order_data ) {

	if ( wpdm_query_var( 'wpdmppdl' ) !== '' ) {
		//modify...
		if ( $order_data->order_status == 'Expired' ) {
			$order_data->order_status = 'Completed';
			$order_data->expire_date  = time() + 10;
		}
	}

	return $order_data;
}

However, I still get Sorry! Support and Update Access Period is Already Expired. Will have another try when I’m fresh to see if I missed something.


jdh1178
Participant

Yeh, actually just testing this now and using the getOrder filter won’t work at all for this case unfortunately. The order page is set to Complete because get order runs when loading the page which I didn’t notice at first try.

The page should be expired and all the messaging / logic should remain expired (for renewal actions, upsell etc.). However, it should allow for downloads instead of blocking them in the wpdmpp download() function validity checks. So, unintended consequences using a general filter on order seem unavoidable.

For example (with filter in ‘download()’):
– User goes to order details
– User sees ‘account expired’
– User sees prompts to ‘renew’
– User sees download buttons
– Clicks on them and gets a list of all downloads available up until the expiration.
– User clicks download, the download() apply filter on the order data kicks in
– $odata gets set to ‘complete’ and ‘expire date’ is in future so user is allowed to download
– $odata isn’t’ passed anywhere from that function so it dies there (I think).

With filter using getOrder:
– User goes to order details
– Page is set to Complete (not expired), so they are served everything as if they ‘completed order’
– User doesn’t see renewal instructions etc.

Also it becomes impossible to work around with other solutions like store a global and ‘reset back on before download’ because you can’t ‘getOrder’ again without running the filter again so you end up in a loop.


jdh1178
Participant

@Shahjada the filter works, however, and perhaps I’m overthinking this…but,

if every time we ‘get’ the order data, we are modifying it to change the expiration time and status for example, without knowing where this is happening precisely we run the risk that we commit that (or pass along that info) to somewhere it shouldn’t be. It’s hard for me to know since I don’t know the codebase well, but my gut says that it’s risky vs specifically doing it within a function ( wpdmpp download() ) where the order status is just checked to verify the download function can do it’s thing.

In other words, because the filter is quite general (and used quite often I imagine), the risk of something going wrong increases. It’s definitely handy though to have it this way, but I’m a bit worried of unintended consequences. In that sense having a specific filter in the download() is safer.

Any thoughts? Thanks


jdh1178
Participant

Nice one, thanks will check that out!

Viewing 25 posts - 1 through 25 (of 43 total)