dongqin8652 2016-06-29 05:43
浏览 51

Woocommerce REST API条件JSON

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Matlab问题解答有两个问题
    • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
    • ¥15 gsoap生成onvif框架
    • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
    • ¥15 stm32的can接口不能收发数据
    • ¥15 目标检测算法移植到arm开发板
    • ¥15 利用JD51设计温度报警系统
    • ¥15 快手联盟怎么快速的跑出建立模型