I have tracked down the pages & the code I need to edit, you already have working code written for the Shopping Cart and I just want to be able to implement this in a different spot in the site, so hopefully this research will help along with the Support request.
———————————————————————
Here is the code from the Front-End User Profile: /wpdm-premium-packages/templates/user-dashboard/billing-info.php
———————————————————————
<div class=”form-group col-md-6 “>
<label class=”” for=”billing_country”><?php _e(“Country”, “wpdm-premium-packages”); ?> <i class=”fa fa-star text-danger ttip”
title=”<?php _e(‘Required’, ‘wpdm-premium-packages’); ?>”></i></label>
<?php
$countries = wpdmpp_get_countries();
$allowed_countries = ( isset($wpdmpp_settings[‘allow_country’] ) ) ? $wpdmpp_settings[‘allow_country’] : array();
?>
<select class=”required wpdm-custom-select form-control” id=”billing_country” name=”checkout[billing][country]”>
<option value=””><?php _e(‘–Select Country–‘, ‘wpdm-premium-packages’); ?></option>
<?php
foreach ($countries as $country) {
if ( ! empty( $allowed_countries ) ) {
if( in_array( $country->country_code, $allowed_countries ) )
echo ‘<option value=”‘ . $country->country_code . ‘”‘ . selected( $billing[‘country’], $country->country_code, false ) . ‘>’ . $country->country_name . ‘</option>’;
} else {
echo ‘<option value=”‘ . $country->country_code . ‘” ‘ . selected( $billing[‘country’], $country->country_code, false ) . ‘>’ . $country->country_name . ‘</option>’;
}
}
?>
</select>
<span class=”error help-block”></span>
</div>
</div>
<div class=”row row-fluid”>
<div class=”form-group col-md-6 “>
<label class=”” for=”billing_state”><?php _e(“State/County”, “wpdm-premium-packages”); ?> <i class=”fa fa-star text-danger ttip”
title=”<?php _e(‘Required’, ‘wpdm-premium-packages’); ?>”></i></label>
<input type=”text” id=”billing_state” name=”checkout[billing][state]” data-placeholder=”<?php _e(“State/County”, “wpdm-premium-packages”); ?>”
value=”<?php if (isset($billing[‘state’])) echo $billing[‘state’]; ?>” class=”input-text required form-control”>
<span class=”error help-block”></span>
</div>
———————————————————————
So for the [input:select] I can see it looping through the array to give the Country pull-down & I can see the [input:text] for the State. So obviously here there is no connection between the two form fields.
———————————————————————
———————————————————————
Here is the working code from the Shopping Cart: /wpdm-premium-packages/templates/checkout-cart/checkout-billing-info.php
———————————————————————
<div class=”form-group”>
<div class=”row”>
<div class=”col-md-6″>
<label class=”control-label”><?php echo __(“Country”, “wpdm-premium-packages”); ?> <span class=”required” title=”<?php _e(‘Required’, ‘wpdm-premium-packages’); ?>”>*</span></label>
<div class=”controls”>
<?php
$allowed_countries = get_wpdmpp_option(‘allow_country’);
$all_countries = wpdmpp_countries();
?>
<select id=”country” name=”billing[country]” required=”required” class=”custom-select wpdm-custom-select form-control <?php echo wpdmpp_tax_active() ? ‘calculate-tax’ : ”; ?>” data-live-search=”true” x-moz-errormessage=”<?php echo __(“Please Select Your Country”, “wpdm-premium-packages”); ?>”>
<option value=””><?php echo __(“–Select Country–“, “wpdm-premium-packages”); ?></option>
<?php foreach ($allowed_countries as $country_code) { ?>
<option value=”<?php echo $country_code; ?>” <?php selected( $billing[‘country’], $country_code, true ); ? <?php echo $all_countries[$country_code]; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class=”col-md-6″>
<label class=”control-label”><?php echo __(“State / Province”, “wpdm-premium-packages”); ?> <span class=”required” title=”<?php _e(‘Required’, ‘wpdm-premium-packages’); ?>”>*</span></label>
<div class=”controls”>
<select id=”region” name=”billing[state]” type=”text” class=”custom-select wpdm-custom-select form-control <?php echo wpdmpp_tax_active() ? ‘calculate-tax’ : ”; ?>”></select>
<input id=”region-txt” style=”display:none;” name=”billing[state]” value=”<?php echo $billing[‘state’]; ?>” type=”text” placeholder=”<?php echo __(“state / province / region”, “wpdm-premium-packages”); ?>” class=”form-control <?php echo wpdmpp_tax_active() ? ‘calculate-tax’ : ”; ?>”>
<p class=”help-block”></p>
</div>
</div>
</div>
———————————————————————
Here I can see the two [input:selects]. Obviously there are associated functions which load the ‘State / Province’ form field with the right data.
———————————————————————
———————————————————————
Unfortunately when I copy the new ‘State / Province’ code over all I get is a blank [input:select], so I’m guessing [checkout-billing-info.php] the functions aren’t available to [billing-info.php].
I’m sure it’s not hard but I just haven’t been able to find the link and would appreciate a bit of help ๐
Well, I seem to have identified the problem. I went digging into the server files and not only noticed that some cache files were there but totally blank, but more importantly noticed that for the packages that worked there was:
ONE file: /uploads/wpdm-cache/*-48×48.jpg
however for the packages with the coding error there were:
TWO files: /uploads/wpdm-cache/*-48×48.jpg AND /uploads/wpdm-cache/*-48×48.JPG
Went back and re-created the packages but now with the file extension changed from *.JPG to *.jpg and they all work fine. Double-checked with *.JPG and get the error.
SO IT IS THE CAPITAL FILE EXTENSION OF THE ORIGINAL UPLOAD THAT WAS CREATING ALL OF THE PROBLEM
Why? No idea. Even though UNIX is case-sensitive there is no way that this should be causing such a glitch – capitalised or not it is a valid file extension. My Canon camera defaults to a *.JPG file extension, so I will just have to make sure I change these before uploading.
How to stop the issue happening for other sellers?
Well unfortunately this isn’t an especially ‘professional’ solution. Although I can specify Allowed File Types From Front-end: AND this field is CASE-SENSITVE (ie. I can specify jpg, JPG) the check code isn’t recognising the capitilastion so even if I only specify [jpg] it still let’s me upload [JPG].
Although re-writing the check code for these ‘allowed file types’ to be case-sensitive match would be an improvement (OR Writing the front-end code to catch the error elegantly), the fact that U-Case is causing such an issue suggests that the code would be better off defaulting all filenames & extensions to L-case.
This is especially important if this turns out to be a server-side setting (I have asked) because then the code becomes signifcantly more robust
These will definitely not be child-theme edits, so for the moment I will just add *warning* text on the upload screen. Not ideal, but at least folks will know *why* the error is occurring.
Allowed File Types From Front-end:
** UPDATE **
From the last session testing adding new packages this is the result – ONLY the FIRST package uploaded *.jpg created the Thumbnail Image next to the uploaded file, all of the following either displayed just an icon or, in some cases, nothing.
I tested again today using BOTH the *.jpg that worked and another (same everything except content), and guess what? NEITHER FILE CREATED THUMBNAILS
Tried opening & saving files from Mac OS Preview (instead of GIMP) AND another OS (Win 7) and software package Canon’Digital Photo Professional’ (which even gives an error log for output conversion AND optional retaining all of the camera information) – still no thumbnails.
IMHO Based on this is ‘cannot’ be the *.jpg file causing the issue, and the fact that a COUPLE (I think it is a total of 2/35 ) uploads DID WORK makes this incredibly difficult to debug.
So at this point I just want to turn off the code completely (as it doesn’t ‘seem’ to affect the front end apart from giving erors) BUT having some insight as to where, what and any unexpected consequences of turning off the functions would be greatly appreciated…..
The two issues I *still* have are:
1. More often than not I get the error when I first open the Admin Page in WP Dashboard – but as soon as I reload the page the error disappears.
2. I have just created two new packages from the Front End – both containing *.jpg files taken by the same camera, post-processed in the EXACT same method using the EXACT same software. Package A. uploaded the file and created a nice thumbnail – Package B. also uploaded the file fine but didn’t create a thumbnail, instead I get an icon.
I then opened Package B. in another browser as a public user I get the error – again once the page is refreshed the error seems to dissipate.
So from here it seems like there is some sort of glitch happening (more often thatn not) as the code tries to create the thumbnails
As I’m uploading everything myself it’s currently not an issue, but if I get other sellers on the site it’s clearly not a desirable behaviour – anyone knw where I should start looking?
I couldn’t wait so I went a bt further but STILL need to know where in the DB the Role-based commissions are set. I can’t see them anywhere in the [_ahm tables] so I’m guessing it’s somewhere in WP default tables?
I hard coded the SQL insert [/libs/class.Order.php] because I really wanted to see what happens if there is data in the [_ahm_order_items][site_commission] field in regards to Sales display at the Seller end (/wpdm-pp-earnings.php).
I also hard-coded the function wpdmpp_site_commission($uid = null) so that it gives a GLOBAL SITE PERCENTAGE (I set $comission = 35; – yes this is the correct spelling for the variable, easy typo to do!)
I have also hard-coded a MIN commission value so that if the calculated commission is always at least the MIN value.
Although I can’t test to see what is happening if the commission percentage values are being read from the DB, I am not sure I agree with the following calculations.
Point 1. I like the ability to write a [site_commission] value into the order record as it gives the commission value calculated AT THE TIME OF THE ORDER.
Point 2. If the [site_commission] value IS ZERO then the code is calculating the commission based on the current GLOBAL SITE PERCENTAGE, even if at the time of the order it was different. The merit of this can be argued either way.
The main problem I see is that the code is calculating the sales commission in real-time, and it is not using the [site_commission] value even though it using this value to display. Here is the Dashboard display for three sample orders.
Price Commission Earning [site_commission] value
$36 $12.60 $23.40 12.6
$12 $4.20 $7.80 0
$10 $5.00 $5.00 5
So far so good. It is the totals that is the problem.
$58.00 $20.30 $37.70
12.6 + 4.20 + 5.00 = 21.8…….
So although it DISPLAYS the [site_commission] value, it calculates the totals from the price * current commission percentage – in this case the hard-coded 35%.
12.6 + 4.2 + (10*0.35) = 20.3
What this means for my install is that if I want to use a MIN commission value I’m gonna need to rewrite this code so that I don’t over pay the sellers. However I also wondered if this might not be an issue for other installs if they were to change their commissions AFTER a Payout Withdrawal has been requested?
A couple of extra notes.
Although you can switch off User Role discounts & Package Coupon codes from Settings > Premium Packages, this only turns off the field display in the Cart, pretty well any other page that renders an order shows these as column headers and 0.00 content – hence the hard-coding to completely remove this from displaying.
Whilst modifying these files I also modified: wpdm-premium-packages/templates/partials/order-notes.php
I don’t mind the [ADD NOTE] option but for the purchaser to easly contact the site admin or seller, but I really didn’t want them being able to UPLOAD files without having a lot more control over what, how big, how many, etc……. so that was also hard-coded out.
Cheers ๐
I have figured out a solution that works well. ONLY select [Pages] in the theme settings (the other options, including POST give inconsistent resluts) and add the following to functions.php.
function search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set(‘post_type’, ‘post’);
}
}
}
add_action(‘pre_get_posts’,’search_filter’);
Now the text search works perfectly across pages and downloads!
FWIW I have modified the site to appropriately calculate and display Australian GST.
Standard package pricing is default GST Inclusive and the tax now simply calculates the GST component of the order total rather than adding it (which is the default WPDM Premium Packages behaviour). As previously noted the site now hard-codes tax at 10% so that it automatically displays GST at the Cart no matter what country you have selected (guest orders included).
———————————
Files requiring editing were:
Account Holder Order Summary Page
/wp-content/plugins/wpdm-premium-packages/templates/user-dashboard/order-details.php
Guest User Order Summary Page
/wp-content/plugins/wpdm-premium-packages/templates/partials/guest-order-details.php
Invoice Page
/wp-content/plugins/wpdm-premium-packages/templates/wpdm-pp-invoice.php
All of these pages will seamlessly over-ride the default code if correctly placed in a child-theme!
————
Note: whilst changing calculations and page layouts I picked up an inconsitency with the way Coupon Discounts are displayed. The problem originates from having TWO methods to create a Coupon Discount:
1. Assign it to a PACKAGE (id)
2. No Package Assigned = GLOBAL
The code ASSUMES the Coupons are working at a Package level, so if you are using them ‘globally’ (which is what I am doing) then they do not display at order summary pages or on the invoice, which was quite confusing until I worked out what was happening. The code really needs a few extra IF statements, however because the code is using hard-coded table headers AND THEN looping code it’s a bigger task to rewrite these pages in that way.
So instead I have also edited the WP Admin panel code to remind myself NOT to use the Package ID, leaving the structural part of the code untouched.
/wp-content/plugins/wpdm-premium-packages/includes/menus/templates
In the context of trying to never change structural process code, I also didn’t change any WP Dashboard Admin page code, because the User will not see these and I know what is happening here.
I also hard-coded OUT the display of the Role Discounts, because I won’t be using them and again these were hard-coded into table headers they were a bit confusing to the end user if not being used.
Anyway just letting folks know Australian GST can be done!
Yeah I know how the Search Widget works – however IMHO a text string search that only searches packages is a bit misleading.
The curious part is the ‘default’ search is clearly being influenced by code coming from your theme Verse – as it presents the different sections that I have selected in the Admin panel. That’s why I’m wondering if it is a Theme code question.
Hmm. All uploaded files are jpg exported directly from GIMP, and checking an example image at http://fotoforensics.com also reports filetype [image/jpg] – which is the same as what the WP Media library reports the file type as.
From what I can tell the user does not have any ‘selection’ of the file type (ie choosing jpg or png) – they just upload the file with the extension.
The next time I get the error I will use another image editor program to open/save the files and I’ll see if this makes any difference.
Downloads > settings >Frontend Access also has the following ‘Category Page Options’
Use Basic Style
OR
Use Link Template
——
Again nothing seems to change at the front end no matter what I select here, even using my ‘<div>just contains text to see what happens</div>’ template ๐
Well I thought sorted ๐
When I clone a ‘Link Template’ and add the [categories] shortcode the ‘preview’ shows that the categories will be displayed. So I figured just change the Link template yes?
However the issue I have is that no matter what Link or Page Template (and I mean any, not just the cloned one) I chose for a package the front-end layout stays exactly the same?
Sorted. I can see that by cloning a template you have the option to add the shortcode. Now hopefully I can figure out how to text string search it……
BTW the source HTML for a package includes the text strings……..example below.
<div class=”post post-146 wpdmpro type-wpdmpro status-publish has-post-thumbnail hentry wpdmcategory-21 wpdmcategory-sa-ashbourne wpdmcategory-date wpdmcategory-ducati wpdmcategory-22 wpdmcategory-manufacturer wpdmcategory-public-ride wpdmcategory-sa wpdmcategory-ducati-st wpdmcategory-type wpdmcategory-where”>
If I can get the Order & Invoice pages to display all the order details (in another Topic!) I think these tax edits will work. Still need to go through and change ‘Tax’ to ‘GST’ ๐
FYI it is my suggestion that whenever you do financial calculations all results, no matter how simple it seems, are written into the database record. By doing this you should never need to perform any further mathematical calculations on the data, so there is never any possibility of a mis-match, no matter how the data is subsequently presented
I stand corrected, it does look like you are writing all the values into the DB. I had missed a line (another) of calculating code….
Maybe this will work after all….I’ll update shortly!
I folder-level searched through the plugin code and have turned off any instances of [$total += $tax] or [$order_total = $subtotal + $tax;]
/wpdm_premium_packages/wpdm_premium_packages.php
/wpdm_premium_packages/includes/lib/class.Order.php
/wpdm_premium_packages/includes/lib/cart.php
This displays the ‘tax inclusive’ package price correctly and displays the tax component correctly at the Cart, even with two products and a Coupon Code. And the Guest Order also writes into the DB OK [subtotal:20, tax:1, cart_discount:0, coupon_discount: 10]. Order ID: wpdmpp5D40E99DA3A8D
BUT….here is the domino effect
1. https://www.motoshoot.com.au/purchases/?id=wpdmpp5D40E99DA3A8D
2. https://www.motoshoot.com.au/guest/?id=wpdmpp5D40E99DA3A8D&wpdminvoice=1
Again in both instances the code is automatically adding the subtotal and the tax.
BTW although deducting the Coupon Discount value correctly it is not displaying the field anywhere here? There are a few other glitches here so I have started a new Forum Topic ‘Guest Order/Invoicing Problems’
I have done an extended search through the other plugin folders but aren’t matching the $total, $subtotal or $tax strings. So apart from not knowing WHERE thiscalculation is happening, based on the way the code is written I am again thinking that leaving everything as default code but simply changing the way the package price is displayed at the FRONT END is probably the safest option.
But where is this done?
FYI it is my suggestion that whenever you do financial calculations all results, no matter how simple it seems, are written into the database record. By doing this you should never need to perform any further mathematical calculations on the data, so there is never any possibility of a mis-match, no matter how the data is subsequently presented ๐
Shahriar, yes this is a simple solution, but it won’t work because I have to be able to show the customer the TAX component.
Therefore I have to have the Cart code calculate and display Tax, and at the moment it adds the Tax. I can see in the code where it does this, but I’m pondering whether trying to make it work the ‘other’way around is too much of a ‘custom’ code change. IMHO major changes (any really) to financial code really needs lengthy and robust beta-testing & debugging.
So that’s why I’m wondering if it isn’t a simpler to just change to ‘displayed’ prices at the front end. I’m pretty happy working out the code changes (not complicated) really just after pointers on which files I should be looking at.
Adrian
Thanks Shahriar for quick reply. I pasted the code into functions.php and the result of searching for a known package (8813) is now this:
1. Search still seems to default to ‘Posts’ – as the [Posts] search menu is highlighted at the results screen. The new code breaks my previous edit though and there is no text repsonse at all to a ‘no results’ search.
2. Curiously though when I switch the search menu to [Pages] it gives me a hit on the package……which is doesn’t do under normal Search conditions. Not sure where/how the search string is matching here.
3. As per before it matches when the menu is switched to [Downloads]
Adrian