Pawan Kumawat

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

Add to cart duplicates products on refresh page?   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 cart.   This is because when add to cart process is not executed using ajax , than it is executed by query string. When Adding product to cart using query string, URL becomes something like this”?add-to-cart=1234&quantity=1” so when we refresh the page, this will again execute and product will again add to cart. So to Remove This Issue We have To redirect the page after add to cart.   There is a option in WooCommerce that lets you redirect customers directly to the cart when they’ve

Display a Product Category Dropdown and Redirect To Single Category Upon Selection.

How To add category dropdown Before WooCommerce product loop? WooCommerce product loop is generally on shop page and category page. on both pages WooCommerce provide hooks before the loop and after the loop. “woocommerce_before_shop_loop” “woocommerce_after_shop_loop” For adding a category dropdpwn or other texonomy dropdown We will use “woocommerce_before_shop_loop”.   For Both Product loop. (shop page and category page) function CategorySwitcher() { wc_product_dropdown_categories(); $category_base=get_option(‘woocommerce_permalinks’)[‘category_base’]; wc_enqueue_js( ” (‘#product_cat’).change(function () { location.href = ‘”.site_url().’/’.$category_base.”/’ + $(this).val(); }); “); } add_action(‘woocommerce_before_shop_loop’,’CategorySwitcher’,100); For Only Category Archive Page.   function CategorySwitcher() { if ( is_product_category() ) { wc_product_dropdown_categories(); } $category_base=get_option(‘woocommerce_permalinks’)[‘category_base’]; wc_enqueue_js( ” (‘#product_cat’).change(function () { location.href = ‘”.site_url().’/’.$category_base.”/’ + $(this).val(); }); “); } add_action(‘woocommerce_before_shop_loop’,’CategorySwitcher’,100); For Only Shop Page.   function CategorySwitcher() { if ( is_shop() ) { wc_product_dropdown_categories(); } $category_base=get_option(‘woocommerce_permalinks’)[‘category_base’]; wc_enqueue_js( ” (‘#product_cat’).change(function () { location.href = ‘”.site_url().’/’.$category_base.”/’ + $(this).val(); }); “); } add_action(‘woocommerce_before_shop_loop’,’CategorySwitcher’,100);  

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

How to add the same product twice to cart instead of changing quantity in WooCommerce   In normal case when we increase quantity of product in WooCommerce cart it simply increase quantity of same product that’s one product with incremented quantity. But 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. Basically we need to display separate cart items for product quantity > 1. We can do that with pasting the code To the functions.php of theme.   This Is Done Basically In Two Steps:   Step 1: Split product quantities into multiple cart items.   In This Hooks Basically, when we are adding a new product to cart ,we have added a unique key to each cart item meta. that’s why the same product become distinct product each time. For

Disable Automatic Login After Registration

When we enable customer registration on My Account page, We will know that when new user is register it’s automatically logged in .
it need to change when we need to manually approve each user.

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

Do you ever need to replace the default WooCommerce pricing label for a free product?   If we ask any user what will he/she like the text “FREE” or a price tag of “0.00”. Majority will say “Free” Attracts More.   Now Let’s talk about WooCommerce ,In WooCommerce when product price is zero or empty then on cart page or checkout page and product page will show zero price ($0.00). Instead of showing the default WooCommerce pricing label of $0.00, you want to show custom text,like “FREE” or “Download Now”. In Previous Image we so price tag , But I still believe “FREE” looks much better than “$0.00”. It’s much more enticing, isn’t it?   For Cart and Checkout Page:   function FreeCartItemPriceCustomLabel( $price, $cart_item, $cart_item_key ) { $FreeLabel = ‘<span class=”amount” style=” color: #f7ad06 !important; “>’ . __(‘Free’) . ‘</span>’; if( $cart_item[‘data’]->get_price() > 0 ){ return $price; }else{ return

Change the WooCommerce Breadcrumb Text.

To change the WooCommerce breadcrumb text, you can use the `woocommerce_breadcrumb_defaults` filter hook to modify the default breadcrumb settings. This filter allows you to customize the breadcrumb separator and labels as per your requirement. Here’s how you can change the WooCommerce breadcrumb text: 1. Open your theme’s `functions.php` file or a custom plugin file. 2. Add the following code to customize the breadcrumb text: function custom_change_woocommerce_breadcrumb($args) { // Customize breadcrumb separator (optional) $args[‘delimiter’] = ‘ > ‘; // Customize breadcrumb labels $args[‘home’] = ‘Custom Home’; $args[‘shop’] = ‘Custom Shop’; $args[‘singular_name’] = ‘Custom Item’; return $args; } add_filter(‘woocommerce_breadcrumb_defaults’, ‘custom_change_woocommerce_breadcrumb’); In this code, we use the `woocommerce_breadcrumb_defaults` filter to modify the breadcrumb settings. The `custom_change_woocommerce_breadcrumb` function receives the default breadcrumb settings as `$args`. You can customize the following breadcrumb settings: – `$args[‘delimiter’]`: This sets the separator between breadcrumb items. In the example, we use `’ > ‘` as the separator. You can

Categories