Ajax search pro advanced option – Combining custom fields with custom function
-
My problem is that I can’t combine that custom fields with custom function. For example combining ‘post_title’ custom field with the custom stocks( Display the stock availability for all product types in Woocommerce archive pages) that i’ve inserted on my function.php isn’t possible, to have something like this combination Oppo – 12pc.
I would like to use some special combinations between custom fields and:
Custom stocks function instead of the default _stocks.
How can I could achieve this?
this is my code:
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 '<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 ); } }
Thanks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Ajax search pro advanced option – Combining custom fields with custom function’ is closed to new replies.