Hi
I am creating a Post Edit/Renewal Form with Cred Commerce option. So It means, there will be a payment option involved when this edit form is submitted. And my exact requirement is something like below.
My edit form is designed in a way like, I have a taxonomy single select field which is auto-selected based on the post's exiting data. and I don't let user change the taxonomy categories in this edit form, and just ask users to renew the post by paying the appropriate amount. Now the renewal fee is applied based on the existing selected category. So to define the appropriate price for the renewal, I have assigned a custom field which is considered as a select field that has values with WooCommerce Product IDs, and I have created these product id's Option values with jquery. and previously this function was working perfectly but now for this edit form its not working. And it only works if I change the category field option.
But I want that my cost field "property-ad-cost" field should auto select the value based on the pre-selected category value when the edit form is loaded.
------------------------
Category Field:- property-ad-type[]
Cost assigning field:- wpcf-property-ad-cost
------------------------
Please see the code.
jQuery(document).ready(function($) {
$("[name='property-ad-type[]']").change(function() {
var val = $(this).val();
if (val == "106") {
$("[name='wpcf-property-ad-cost']").html("<option value='1105'>Featured Property Ad</option>");
} else if (val == "107") {
$("[name='wpcf-property-ad-cost']").html("<option value='1007'>Property Photo Ad (Free)</option>");
} else if (val == "105") {
$("[name='wpcf-property-ad-cost']").html("<option value='1519'>Slideshow Walk through Ad</option>");
} else if (val == "104") {
$("[name='wpcf-property-ad-cost']").html("<option value='1520'>Video Walkthrough Ad</option>");
} else if (val == "108") {
$("[name='wpcf-property-ad-cost']").html("<option value='2529'>Text Only Ad (Free)</option>");
}
});
});
Please help me to fix this code to work when the form is loaded successfully, So this "property-ad-cost" should automatically assign the value based on the current taxonomy field value.
Please watch the below video demonstration.
hidden link
So As you can see in the video, when page loads, it has a category already selected in taxonomy field, But property ad cost field was blank, but as per my requirements, the above jquery should auto-fill the selected category id based product id in the property ad cost field.
I know that this jquery is for the onChange event. But can you please make a quick tweak in this code so that It can work on page load event.