How to make both City and Postcode fields required in WooCommerce Shipping Calculator
Both the City and Postcode/ZIP fields in the WooCommerce Shipping Calculator are not compulsory for the user to fill in, you may need them mandatory for a better user experience to calculate certain shipping conditions. Both the Suburb and Postcode fields are input fields inside a form which allows us to use the required attribute,…
Read MoreChange the Additional Information Placeholder Text field in WooCommerce
You can change the WooCommerce Additional Information placeholder text field in the checkout page with the woocommerce_checkout_fields filter. Use it in your themes functions.php file like so… add_filter( ‘woocommerce_checkout_fields’ , ‘wpb_custom_additional_info’ ); // Change placeholder text in Additional Notes function wpb_custom_additional_info( $fields ) { $fields[‘order’][‘order_comments’][‘placeholder’] = ‘Any additional notes for delivery’; return $fields; } Change…
Read MoreAdd WooCommerce Action Hook via Shortcode
Some WordPresss WooCommerce templates provided by themes or page builders may not include all the WooCommerce action hooks which may hinder your woo development as you add in more Woo featured, luckily it is possible to add in Woo hooks with shortcode. add_shortcode( ‘woohook’, function( $atts ) { $atts = shortcode_atts( array( ‘hook’ => ”,…
Read MoreFilter & Change WooCommerce ‘Place Order’ Text Button on Checkout Page
You can filter and change WooCommerce’s ‘Place Order’ Text Button on the Checkout Page using the filter woocommerce_order_button_html The default mark up of the Place Order checkout button is: <button type=”submit” class=”button alt” name=”woocommerce_checkout_place_order” id=”place_order” value=”Place order” data-value=”Place order”>Place order</button> You can use the filter like so: add_filter( ‘woocommerce_order_button_html’, ‘custom_order_button_html’); function custom_order_button_html( $button )…
Read MoreAdd a required checkbox field in WooCommerce checkout page
Here is how you can add a required checkbox field in the WooCommerce checkout page that forces a user to checkbox the request before they can proceed to payment, similar to the terms and condition checkbox. WooCommerce Form Field Add the code in your functions.php – the example uses the a new checkbox field named…
Read MoreRemove WooCommerce CSS Styles and Scripts From Pages That Don’t Need It
WooCommerce loads three core CSS style sheets on every page and post when installed on a WordPress site. You can save a bit of page load time here by removing the styles and scripts from pages and content that do not need it . It also loads a bunch of other javascripts and CSS styles…
Read MoreAdd a CSS class to WooCommerce Shop Page
Using the filter body_class with the is_shop conditional you can target the main WooCommerce shop page by adding a CSS class. add_filter( ‘body_class’, ‘woo_shop_class’ ); // Add WooCommerce Shop Page CSS Class function woo_shop_class( $classes ) { if ( is_shop() ) // Set conditional $classes[] = ‘woo-shop’; // Add Class return $classes; } The above…
Read MoreRemoving the Product Meta ‘Categories’ on a Product Page – WooCommerce
WooCommerce product categories are displayed at the bottom of a product page just under the add to cart button. You can remove these from the layout by removing the woocommerce_template_single_meta action from the product summary, in your themes functions.php add in … remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_meta’, 40 ); This will remove the categories aka product meta from…
Read MoreSort WooCommerce products in cart order by price
By default the WooCommerce cart is ordered by when products are ordered in sequence, this can be manipulated with the woocommerce_cart_loaded_from_session hook. A new array is created $products_in_cart and the carts content is looped with the key of the array being the price $product->get_price(), the array is then sorted with asort or arsort before being…
Read MoreSort WooCommerce products from product category to be last in cart order
From a selected WooCommerce product category sort products to be at the end of a carts order. add_action( ‘woocommerce_cart_loaded_from_session’, ‘product_category_cart_items_sorted_end’ ); /** * WooCommerce – sort some Prod Cat items to be last order in cart * @link https://stackoverflow.com/questions/65800801/sort-specific-product-category-cart-items-at-the-end-in-woocommerce */ function product_category_cart_items_sorted_end() { $category_terms = __(‘box’); // Here set your category terms (can be names,…
Read More