Welcome to WP Beaches

WordPress Websites design specialists, based in the Northern Beaches, Sydney
Design, Develop, Host


Sort WooCommerce products in cart order by price

Sort Woocommerce 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…

Sort WooCommerce products from product category to be last in cart order

Woocommerce Cart Product Category Last

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,…

WooCommerce cart total count minus certain product category

Woocommerce Increment Quantities Cart

I have a client that sells boxes and units of a product – for the units they need to be sold in multiples of 6, for the boxes it doesn’t matter, so I need the cart total to be less the boxes total and checked to see if it is divisible by 6 – if…

Set WooCommerce cart product count total to be divisible by number

Number Of Products Woocommerce

You can set WooCommerce cart total product count to be divisible by a certain number, if it is not divisible by that number then do not allow the user to checkout. add_action( ‘woocommerce_check_cart_items’, ‘check_cart_items_conditionally’ ); /** * Check cart items conditionally displaying an error notice and avoiding checkout * @link https://stackoverflow.com/questions/65767078/disable-woocommerce-checkout-if-cart-items-count-is-not-a-multiple-of-n */ function check_cart_items_conditionally() {…

Stop WooCommerce checkout fields auto-filling – leave blank

Woocommerce Empty Checkout

You can stop WooCommerce checkout fields from auto filling by using a Woo filter woocommerce_checkout_get_value, this could be useful in a situation when a logged in user is ordering on behalf of multiple customers. add_filter( ‘woocommerce_checkout_get_value’,’prefix_return_empty_checkout’, 1, 1 ); function prefix_return_empty_checkout(){ $user = wp_get_current_user(); //The user has the “shop_manager” role if ( in_array( ‘shop_manager’, (array)…

Add a menu to WordPress page with PHP action hooks

Add WordPress Menu Php

Adding a menu to WordPress via PHP and action hooks requires three steps, registering the menu location, assigning a menu to it and then placing the menu with an action hook. Register WordPress Menu Registering a menu is done with register_nav_menu, below is an example to register a ‘Store Menu’ menu. add_action( ‘init’, ‘wpb_custom_new_menu’ );…

How to turn off Auto-correct on macOS Big Sur for all applications

Macos Autocorrect Disabled

Auto-correct seems to be enabled by default in some macOS computers which can be a pain especially in Mail, and any application which you are typing a lot and simply don’t need it. Here is how to turn off auto-correct for macOS applications. Put a stop to It Globally Go to the Apple Menu >…

Change WooCommerce SKU text to another label

Woocommerce Sku Label.peg

You can change WooCommerce SKU text to another label using the gettext filter add_filter(‘gettext’, ‘translate_woocommerce’, 10, 3); /** * Change SKU Label * @link https://gist.github.com/dannyconnolly/da6f1a2d95dc826ccdcd * @since 1.0.0 */ function translate_woocommerce($translation, $text, $domain) { if ($domain == ‘woocommerce’) { switch ($text) { case ‘SKU’: $translation = ‘Catalogue No:’; break; case ‘SKU:’: $translation = ‘Catalogue No:’;…

Show only free shipping option on WooCommerce cart and checkout pages

Woocommerce Free Shipping Option

By default WooCommerce will show all available shipping options on cart and checkout pages, if you have free shipping as an option you may just want that displayed by itself. The code snippet below which needs to be added to your functions.php theme file will do just that… add_filter( ‘woocommerce_package_rates’, ‘prefix_hide_shipping_when_free_is_available’, 100 ); /** *…