Skip to main content

Change WooCommerce unit from Price to Kilogram


How to Change WooCommerce unit Price to Kilogram

Just Simply follow these steps below:

Step 1: ​First is go to your Dashboard -> Appearance -> Editor -> Theme Function

Step 2: Scroll down to the bottom of the code section and insert the following code:


add_filter( 'woocommerce_get_price_html', 'wb_change_product_html' );
 // Change and return $price_html variable using the $price and weight amount
 function wb_change_product_html( $price ) {
  $price_html = '<span class="amount">' . $price . ' per kg </span>'; // change weight measurement here
 
  return $price_html;
 }
 
 add_filter( 'woocommerce_cart_item_price', 'wb_change_product_price_cart' );
 // Change the cart prices with $price variable and weight amount
 function wb_change_product_price_cart( $price ) {
  $price = $price . ' per kg'; // change weight measurement here
 
  return $price;
 }
 
 add_filter( 'woocommerce_checkout_cart_item_quantity', 'wb_checkout_review', 10, 3 );
 // Change the checkput prices with $cart_item variable and weight amount
 function wb_checkout_review ( $quantity, $cart_item, $cart_item_key ) {
  
  $cart_item = ' <strong class="product-quantity">' . sprintf( '&times; %s', $cart_item['quantity'] ) . ' kg </strong>'; // change weight measurement here
 
  return $cart_item;
 
 }

Step 3: Click SAVE to Update the File and save the changes.





Congratulations! You can now sell your products by Kilo in your store.



Thank you!






Comments

Popular posts from this blog

How to add your Source Code to GitHub

Quick setup  — if you’ve done this kind of thing before  Set up in Desktop or HTTPS SSH Get started by  creating a new file  or  uploading an existing file . We recommend every repository include a  README ,  LICENSE , and  .gitignore . …or create a new repository on the command line echo "# bms" >> README.md git init git add README.md git commit -m "first commit" git branch -M main git remote add origin https://github.com/xxxxxxxxx/bms.git git push -u origin main …or push an existing repository from the command line git remote add origin https://github.com/xxxxxxxxxx/bms.git git branch -M main git push -u origin main -------------------------------------------------------------------------------------------------------- Proper steps to add existing code to GitHub The proper way to push a new project into an existing GitHub repository follows these steps: Create a GitHub repository for the existing project. Copy the GitHub URL for th...

How to connect your Website domain name to a Cloud VPS hosting environment running XAMPP

To connect your Website domain name to a Cloud VPS hosting environment running XAMPP, follow these steps: Obtain Your VPS IP Address : Log in to your Contabo account and navigate to your VPS management section to find your server's public IP address. Configure Your Domain's DNS Settings : Access your domain registrar's control panel. Locate the DNS management section. Create an 'A' record pointing your domain (e.g., yourdomain.com ) to your VPS's public IP address. If you want ' www.yourdomain.com ' to also point to your VPS, add a 'CNAME' record for 'www' pointing to 'yourdomain.com'. Set Up Virtual Hosts in XAMPP : On your VPS, open the httpd-vhosts.conf file located at C:\xampp\apache\conf\extra\httpd-vhosts.conf . Add the following configuration, replacing placeholders with your actual domain and directory paths: <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "C:/xampp/ht...

How to Create a Bootable USB Using Rufus

  How to Create a Bootable USB Using Rufus A “ bootable USB ” is a regular USB storage device (like a USB stick or external hard drive) that has an “ISO image” of an operating system saved on it.   An ISO image is an archive file that contains all the information found on an optical disc, such as a CD or DVD. This could, for example, be a Windows installation CD. Normally, whenever you start up your computer, it boots from the operating system stored on your internal hard drive. By running the bootable USB however, you can boot up your computer using the USB’s ISO image instead.  This can be useful if you ever need to recover, repair or install an operating system on your computer. How to Create a Bootable USB using Rufus Rufus is one of several programs that allow you to create an “ISO image” on a USB stick. To create a bootable USB using Rufus, all you need is: Your ISO of choice, e.g. Windows 10 The latest version of Rufus (available online from...