自定义字段ajax搜索

时间:2019-12-31 06:04:14

标签: php html ajax woocommerce

我这里有一个汇总所有产品变化库存的函数。

add_action('woocommerce_after_shop_loop_item','wc_loop_get_product_stock_availability_text',10); 函数wc_loop_get_product_stock_availability_text(){     全局$ wpdb,$ product;

// For variable products
if( $product->is_type('variable') ) {

    // Get the stock quantity sum of all product variations (children)
    $stock_quantity = $wpdb->get_var("
        SELECT SUM(pm.meta_value) FROM {$wpdb->prefix}posts as p
        JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
        WHERE p.post_type = 'product_variation'
        AND p.post_status = 'publish' AND p.post_parent = '".get_the_id()."'
        AND pm.meta_key = '_stock' AND pm.meta_value IS NOT NULL
    ");

    if ( $stock_quantity > 0 ) {
        echo '<p class="stock in-stock" >'. sprintf( __("%s in stock", "woocommerce"), $stock_quantity ).'</p>';
    } else {
        if ( is_numeric($stock_quantity) )
            echo '<p class="stock out-of-stock">' . __("Out of stock", "woocommerce") . '</p>';
        else
            return;
    }
}
// Other products types
else {
    echo wc_get_stock_html( $product );
}

}

我如何使用它在我的ajax搜索中显示?当我使用{_stocks}字段时,结果中不显示股票。这是我在插件中使用的字段的格式。 enter image description here

感谢您的帮助。

0 个答案:

没有答案