WordPress

WooCommerce : Add same product to cart twice instead of changing quantity in Cart Page

In some of cases, We like to have product in WooCommerce added in the cart as separate items and not as the same item with the changed quantity. We can do that with pasting the code To the functions.php of theme. Example : function AddNewProductInsteadChangeQuantity( $cart_item_data, $product_id ) {   $distinctive_cart_item_key = md5( microtime() . rand() …

WooCommerce : Add same product to cart twice instead of changing quantity in Cart Page Read More »

WooCommerce: Programmatically Remove Product From Cart Using Product Id

Many Times in WooCommerce we need to remove a product from cart if a certain condition is met. It’s 3 step process Generate Cart Id From Product Id Then Find Product In Cart Using Product Cart Id. If Product Exist Remove Product From cart. Example : function ProgrammaticallyRemoveProductFromCart() {   if ( is_admin() ) return;   $product_id …

WooCommerce: Programmatically Remove Product From Cart Using Product Id Read More »

WooCommerce : Display “FREE” if Product Price is 0 or Empty On WooCommerce Cart Page Or Checkout Page

In WooCommerce when product price is zero or empty then on cart page or checkout page it will show zero price. But I still believe “FREE” looks much better than “$0.00”. It’s much more enticing, isn’t it? Example : function FreeCartItemPriceCustomLabel( $price, $cart_item, $cart_item_key ) {   $FreeLabel = ‘<span class=”amount” style=” color: #f7ad06 !important; “>’ …

WooCommerce : Display “FREE” if Product Price is 0 or Empty On WooCommerce Cart Page Or Checkout Page Read More »

WooCommerce : Show Only One Error Message on Checkout Field Error

Their are approximately 7 to 10 default field which are required on WooCommerce checkout field. In case these all have error then their are so much error in top, you can see in screenshot below. so for removing or we can say replacing all error with only one msg , you can view in screenshot …

WooCommerce : Show Only One Error Message on Checkout Field Error Read More »

WooCommerce : Custom validation on checkout page for First and Last names to Contain Only Letters

On checkout page two fields are their First name and Last name . user can enter number in it which is not look good because name can’t contain number so for validating it just use ‘woocommerce_after_checkout_validation ‘ to add your custom validation rules and error messages for them. Example : function ValidateFirstnameLastname( $fields, $errors ){ …

WooCommerce : Custom validation on checkout page for First and Last names to Contain Only Letters Read More »

WooCommerce : How to Create a Custom Product Tab on Product page

For Adding Product Tab on Product Page we have to define tab and it’s callback in woocommerce hook ‘woocommerce_product_tabs’. Example : function AddNewTab( $tabs ) {   $tabs[‘my_new_tab’] = array(     ‘title’ => ‘New Tab’,     ‘callback’ => ‘new_custom_tab_content’,     ‘priority’ => 51,   ); } add_filter( ‘woocommerce_product_tabs’, ‘AddNewTab’ ); function new_custom_tab_content($slug,$tab) {   echo ‘<h3>’ . $tab[‘title’] . ‘</h3><p>Add Your …

WooCommerce : How to Create a Custom Product Tab on Product page Read More »

WooCommerce : How to Remove Product Tabs on Product page

The default product tabs On Product page are: Description Additional Information Reviews For Removing These we use woocommerce hook ‘woocommerce_product_tabs’ function RemoveReviewsTab( $tabs ) {   unset( $tabs[‘additional_information’] );   unset( $tabs[‘description’] );   unset( $tabs[‘reviews’] );   return $tabs; } add_filter( ‘woocommerce_product_tabs’, ‘RemoveReviewsTab’ ); Enjoy

WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart.

Generally in WooCommerce clicking on Add-to-Cart and it successfully add the product and display the message that the product is added. And on refreshing the page and message did not disappear and it adds the product once more to cart. And how many times am refreshing the page it is adding the product again to …

WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. Read More »

WooCommerce: Show Required Field Errors Inline on Checkout Page

For Showing inline required error , first we search all fields that are required and have labels , and before the closing label tag we add a span containing error. By default, this is set as display:none, which will be displayed via CSS later. Before: function CheckoutFieldsInlineError( $field, $key, $args, $value ) {   if ( …

WooCommerce: Show Required Field Errors Inline on Checkout Page Read More »

Scroll to Top