0 Answer
  • 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /var/www/html/cnasolution/site/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/site/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/site/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

custom field ajax search

I have here a function which sums up all the stocks of product variation.

add_action( 'woocommerce_after_shop_loop_item', 'wc_loop_get_product_stock_availability_text', 10 ); function wc_loop_get_product_stock_availability_text() { global $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 '

'. sprintf( __("%s in stock", "woocommerce"), $stock_quantity ).'

'; } else { if ( is_numeric($stock_quantity) ) echo '

' . __("Out of stock", "woocommerce") . '

'; else return; } } // Other products types else { echo wc_get_stock_html( $product ); }

}

How can i use this to show in my ajax search? When I used the {_stocks} field, the stocks doesnt show in the result. This is the format of the fields that i've used in the plugin. enter image description here

thanks for the help.

Download script demo [LINK]
Download script demo [LINK 2] Download script demo [LINK 2]