0

I'm using Woocommerce REST API V3 and I want to get a custom JSON callback that is based on a specific element's meta_data (has badge / doesn't have).

If the element has id:14425 - return 1 (it has a badge).

If the element has id:Select badge - return 0 (doesn't have).

This is how metadata looks (I printed it on page just to see the values structure):

[my_product_badge] => Array ( [0] => a:1:{s:2:"id";s:5:"14425";}

Code in wc-api-products.php file (I deleted most of unrelated piece of codes to make it easier to read) :

    private function get_product_data( $product ) {
    $prices_precision = wc_get_price_decimals();
    return array(
        'has_badge' => metadata_exists( 'post', $product->id, 'my_product_badge' ) ? (int) get_post_meta( $product->id, 'my_product_badge', ['id'] && is_numeric , true ) : 0,
    );
}</code>

The results I get back in JSON are not based on the rule of is numeric

Any ideas?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
user3368504
  • 41
  • 1
  • 9

0 Answers0