Hide inventory message on product page based on available stock quantity

Yep! You can check using the get_stock_quantity() method. function my_wc_hide_in_stock_message( $html, $text, $product ) { $availability = $product->get_availability(); $stock_qty = $product->get_stock_quantity(); if ( isset( $availability[‘class’] ) && ‘in-stock’ === $availability[‘class’] && $stock_qty > 1000 ) { return ”; } return $html; } add_filter( ‘woocommerce_stock_html’, ‘my_wc_hide_in_stock_message’, 10, 3 );

Adding Field in WooCommerce

The short, common answer is: Inside functions.php file in your theme. The more advanced answer is: Well… In any file that is included and executed. One way is to create your own plugin and put that line inside it. Another way is to put it in functions.php file in your theme. Remember, that you should … Read more

Adding a custom Shipping methods field to an order

Below is what I used in the end to solve my problem: add_action(‘woocommerce_init’, ‘shipping_instance_form_fields_filters’); function shipping_instance_form_fields_filters() { $shipping_methods = WC()->shipping->get_shipping_methods(); foreach($shipping_methods as $shipping_method) { add_filter(‘woocommerce_shipping_instance_form_fields_’ . $shipping_method->id, ‘shipping_instance_form_add_extra_fields’); } } function shipping_instance_form_add_extra_fields($settings) { $settings[‘route_number’] = [ ‘title’ => ‘Route Number’, ‘type’ => ‘text’, ‘placeholder’ => ‘1,2,3…’, ‘description’ => ‘Enter route number’ ]; return $settings; } … Read more

wc_get_template new template does not showing up

plugin_dir_path( FILE ) will return the current directory. Not sure where you call this q343_get_template() function if it’s on a subdirectory then plugin_dir_path( FILE ) is returning that subdirectory path. From WordPress Code Reference https://developer.wordpress.org/reference/functions/plugin_dir_path/ The “plugin” part of the name is misleading – it can be used for any file, and will not return … Read more

ajax request in wordpress

You can take reference from below code. Remove your ajaxrequest.php file, no need of that file because i have added ajaxrequest.php file’s code in active theme’s functions.php file. I have changed ajax url and add js script code in script.js file. I have tested and it is working for me. let me know if this … Read more