String "Array" populating variable price field
-
Hello!
I am in a similar situation to the user in a resolved thread, in that I’m using WP All Import to populate my Woo products. However on import, something must not be getting set right through just defining the custom fields, as the value stored is a word instead of a number, so nothing is shown on the front-end to US IP addresses (I’m using Canadian as a base currency and only added US so far).
I’ve setup variable product types for import and am populating the following database fields with a “us” price and the manual method for each product post. Here are the custom field name : values I’m setting on import (random price):
_us_price_method : manual
_us_variable_price_method : manual
_us_variable_regular_price : 419
_us_variable_price: 419
_us_price : 419The first two always work, no issues there. The price fields are where the problem seems to stem from.The last one might be overkill but I was trying to match up what I saw change in the post meta database table, if the price was updated on /wp-admin/post.php manually, as opposed to by import job.
Manual post updating of the price works fine or through new product creation.
The issue is that on import instead of a price value showing up under Woo product data on /wp-admin/post.php, it’s just the word “Array”. Looking in the post meta table would show the proper numeric value stored for the custom fields listed above.
I went into /includes/admin/class-wcpbc-admin-product-data.php and executed the following on line 146 inside of product_variable_attributes_countries_prices().
var_dump($_regular_price); var_dump( wc_format_localized_price( get_post_meta( $variation->ID, '_' . $key . '_variable_regular_price', true) ) ); var_dump( get_post_meta( $variation->ID, '_' . $key . '_variable_regular_price', true) );
This returned the following three values, in respective order to the code shown above.
string(5) “Array”
string(5) “Array”
array(1) { [0]=> string(7) “8369.00” }If at this point I replace the word “Array” in the Regular Price field with 8369.00 and save the post, the var_dumps each return: string(7) “8369.00” and the front-end works as expected, displaying the US price to US IPs.
On import 8639.00 is the price I want to populating the price field with, yet can only get “Array” to pup up. I’m not positive but it seems to happen after running wc_format_localized_price().
It seems like my data is being stored correctly but is there something I should be doing while importing to define more settings for the product in relationship to your plugin?
I tried also setting some other db fields, which were not being set on import but would be set if I manually typed in the price, replacing the Array string. It did not fix the issue. At this point the data structure of the same post’s meta fields (import vs post update) appeared to be identical, yet the value array persisted on /wp-admin/post.php under product data…
add_action('pmxi_saved_post', 'post_saved_update_var_ids', 10, 1); function post_saved_update_var_ids($id) { $max_r_ID = get_post_meta($id, '_max_regular_price_variation_id', true); $max_ID = get_post_meta($id, '_max_price_variation_id', true); $min_r_ID = get_post_meta($id, '_min_regular_price_variation_id', true); $min_ID = get_post_meta($id, '_min_price_variation_id', true); update_post_meta($id, '_us_max_regular_price_variation_id', $max_r_ID); update_post_meta($id, '_us_max_price_variation_id', $max_ID); update_post_meta($id, '_us_min_regular_price_variation_id', $min_r_ID); update_post_meta($id, '_us_min_price_variation_id', $min_ID); }
Do you have any thoughts on what may be happening? ?? Anything is much appreciated.
Thank you!
PS.Edit. Some screenshots, albeit from different products. https://imgur.com/a/1AWOZ
https://www.ads-software.com/plugins/woocommerce-product-price-based-on-countries/
- The topic ‘String "Array" populating variable price field’ is closed to new replies.