0

I am stuck and hope you can help me out. I am working on a sidebar widget that shows WooCommerce Shops (I use the Plugin Woocommerce Product Vendors, the official Woocommerce Plugin for multiple user shops). Those shops are basically Terms within the wcpv_product_vendors Taxonomy.

Now when I open a shop (-> opening the single Term) the function get_term_meta( term_id, 'vendor_data', true ) works just fine and gives me an associative array with all my values stored in the termmeta table for my meta_key 'vendor_data'.

But when I am in my widget and I am iterating through a list of shops, and I call get_term_data( id, 'vendor_data', true) the result is false (I give the function the same arguments as on the shop page). If, on the other hand, I call get_term_data( id, '', true) I do get the result I pasted below. Why is that? How can I solve this issue, as it also affects a Widget that comes with the original Product Vendor Plugin (which does not work because of this issue).

Here the var_dump(get_term_data( id, '', true )):

array(1) { ["vendor_data"]=> array(1) { [0]=> string(369) "a:11:{s:5:"notes";s:0:"";s:4:"logo";s:5:"76052";s:7:"profile";s:63:"Description.";s:5:"email";s:16:"shop@xxx.de";s:6:"admins";s:3:"103";s:10:"commission";i:0;s:15:"commission_type";s:5:"fixed";s:6:"paypal";s:0:"";s:20:"per_product_shipping";s:3:"yes";s:15:"enable_bookings";s:2:"no";s:14:"instant_payout";s:2:"no";}" } }

With the filter var_dump( get_term_data( id, 'vendor_data', true )):

bool(false)

The meta_value for key vendor_data within wp_termmeta:

a:11:{s:5:"notes";s:0:"";s:4:"logo";s:5:"76052";s:7:"profile";s:63:"Description.";s:5:"email";s:16:"shop@xxx.de";s:6:"admins";s:3:"103";s:10:"commission";i:0;s:15:"commission_type";s:5:"fixed";s:6:"paypal";s:0:"";s:20:"per_product_shipping";s:3:"yes";s:15:"enable_bookings";s:2:"no";s:14:"instant_payout";s:2:"no";}

EDIT:

I narrowed the issue down to the get_metadata function in which in the end of the function the following checks are done:

if ( ! $meta_key ) {
    return $meta_cache;
}

if ( isset($meta_cache[$meta_key]) ) {
    if ( $single )
        return maybe_unserialize( $meta_cache[$meta_key][0] );
    else
        return array_map('maybe_unserialize', $meta_cache[$meta_key]);
}

This explains: if 'vendor_data' as meta_key is left empty, the 2d-array is returned as posted above. If it is set, and $single is true (which it is as $single is the third parameter), it returns maybe_unserialize(..). I checked this by just returning $meta_cache[$meta_key][0] without the unserialize function and the result is the exact text string that is saved in the database. This means the maybe_unserialize function returns false. But, this is the function:

function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
    return @unserialize( $original );
return $original;

}

In my opinion there is no way this function can return false in just this single case as 1) the function works properly when it's not called from the widget, and the data has not changed, and 2) if data was not properly serialized, the is_serialized would return false and therefore the original input would be returned (and not false).

Please help me: What is going on here?

1

Found the issue.. somehow my serialized string was corrupt, when trying to edit the data in the WP Backend it threw an error and the data was reset. Unserialize now works fine and everything is OK. I don't know if this could help anybody who might be in a similar situation therefore I am not deleting this right now. If a mod thinks this should be deleted feel free to delete it or let me know and I will delete it myself.

  • Yes I know, but I can't yet. Have to wait 2 days before I can accept my own answer :) – Matthias S Nov 15 '16 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.