Two things.
1) the code snippet above will enable the plugin even if it was turned off on the admin because of the else statement that sets enabled to true if the price is at or above 20.00.
2) at the point of completing the order, the subtotal array value doesn't exist anymore because the $order->info is generated from other values which can be used to determine the subtotal, but the subtotal is not used.
Two solutions to the second "problem" come to mind.
1) the "easiest" is to check if the subtotal key exists, if it doesn't then carry on with whatever enabled status was previously set. If it does exist, then compare to your chosen price.
2) if the subtotal doesn't exist, then determine it from say taking the total (which does exist) and subtracting the shipping_cost or the shipping_cost and tax depending on whether DISPLAY_PRICE_WITH_TAX is true or not respectfully.
The function to check for existence of a key in an array would be like:
Code:
array_key_exists('subtotal', $orders->info)
and returns true if it does
Also understand that in a series of and statements: if (true && false && generates_an_error) that php stops processing the logic as soon as any value is false. So it doesn't matter in some regards how incorrect later tests are if an earlier test proved to be false.
As to the else part? I would leave it off so that previous control logic still applied.
Bookmarks