WooCommerce – Create multiple product tags via rest api endpoint

Putting aside whether you’re making the API request from and to the same site or not, I assume that the $woocommerce is an instance of Automattic\WooCommerce\Client. And you can use the batch endpoint for product tags (/wp-json/wc/v3/products/tags/batch) to create/update/delete multiple (by default, up to 100) product tags at a time. Here’s an example for creating … Read more

How to display a table below each product in product list/loop

The shop archive or in general any product-loop that passes through: woocommerce/templates/archive-product.php …or utilizes similar logic found in that template, by calling: wc_get_template_part( ‘content’, ‘product’ ); which retrieves the following template: woocommerce/templates/content-product.php …will then make available the following actions: Excerpt from: woocommerce/templates/content-product.php (version 3.6.0 at the time of this answer) /** * Hook: woocommerce_before_shop_loop_item. * … Read more

Woocommerce Sort by default variation price

get_variation_default_attributes and woocommerce_price are depreciated. This works for me. If I have set default attributes. function custom_variation_price( $price, $product ) { foreach($product->get_available_variations() as $pav){ $def=true; foreach($product->get_default_attributes() as $defkey=>$defval){ if($pav[‘attributes’][‘attribute_’.$defkey]!=$defval){ $def=false; } } if($def){ $price = $pav[‘display_price’]; } } return wc_price($price); }

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