Top 5 Cart Problems in WooCommerce and Their Solutions


WooCommerce is widely used for its vibrant and robust infrastructure for an ideal eCommerce website. It is gaining popularity day by day because of the ease and comfort a merchant enjoys while interacting with target users. The additional features and the user experience design make it a priority for the sellers. Despite the ease of management, still, there are issues that are hard to understand for a layman.

A businessman, who has no exposure to coding or programming, can hardly get the idea to rectify an error. Everyone selects the WordPress and WooCommerce to kick start their business without acquiring expert knowledge or spending lavishly on custom web development. The following issues prove that majority of the WooCommerce users are common people and unable to solve the lame coding issues by themselves.

Following are the few solutions from the experts of Stackoverflow to reduce cart abandonment.

TIP

Use WooCommerce checkout field editor to capture valuable information from customers and avoid cart abandonment.

 

1. Redirecting users from Add-to-cart button to checkout

An eCommerce website is not necessarily about selling products. Normally, a checkout process includes the selection of products and adding them to cart to apply shipping charges etc. For a traditional business, it works perfectly fine, whereas for a service industry it creates hurdles. The service providers need the users to sign up for a program, course, or membership face problems in taking them directly to a checkout page. It is disappointing for their target audience to go through several checkout steps that even don’t apply to the service they need to consume.

If you are using WooCommerce and want your customers to checkout after clicking the Add to cart button, you can set redirection with the following method.

Add this filter in function.php

add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
    global $woocommerce;
    $checkout_url = $woocommerce->cart->get_checkout_url();
    return $checkout_url;
}

The code will surely solve your query for single product pages. If you are using the latest version of WooCommerce i.e. 2.1 or a greater version, then add this simplified function to the code.

function redirect_to_checkout() {
    return WC()->cart->get_checkout_url();
}

2. Overriding the product price in the cart

Merchants are frequently facing the problem of overriding the product price to offer discounts. They often need to alter the product prices to make it easier for a user to checkout. If you are also using WooCommerce and have not customized the pricing mechanism for every customer, you might relate to the difficulty in offering discounts. The pricing remains fixed and a higher amount is charged to the consumer. Following is a quick fix to this problem.

Add this code and you will be able to make changes in the price.

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
$custom_price = 10; // This will be your custome price
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = $custom_price;
}
}

3. Sending Cart items to third party shipping tool

WooCommerce is one of the amazing eCommerce platforms. There is a lot of tools and extension available for managing the shipping of your online store. But, if you are using a third party tool for shipping, you may face difficulty in getting details about cart items. It may be the name, quantity, and price of the product.

An effective solution for this is to apply the below code.

<?php
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
        foreach($items as $item => $values) { 
            $_product = $values['data']->post; 
            echo "<b>".$_product->post_title.'</b>  <br> Quantity: '.$values['quantity'].'<br>'; 
            $price = get_post_meta($values['product_id'] , '_price', true);
            echo "  Price: ".$price."<br>";
        } 
?>

To fetch product image along with the regular and sale price of the product, try this.

<?php
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
        foreach($items as $item => $values) { 
            $_product = $values['data']->post;
            //product image
            $getProductDetail = wc_get_product( $values['product_id'] );
            echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )
            echo "<b>".$_product->post_title.'</b>  <br> Quantity: '.$values['quantity'].'<br>'; 
            $price = get_post_meta($values['product_id'] , '_price', true);
            echo "  Price: ".$price."<br>";
            /*Regular Price and Sale Price*/
            echo "Regular Price: ".get_post_meta($values['product_id'] , '_regular_price', true)."<br>";
            echo "Sale Price: ".get_post_meta($values['product_id'] , '_sale_price', true)."<br>";
        }
?>

4. Applying a discount to your customer order

Giving discounts is one of the proven ways to encourage customers to shop more and bring in more users to a store. For a layman using WooCommerce as a business platform, it is hard to alter the code and made changes. If you need to apply a discount coupon to the entire order of a customers, and the predefined options do not allow you to do so, we offer you an insightful solution.

First of all, you need to create a coupon with the help of this code.

$coupon_code = 'UNIQUECODE'; // Code - perhaps generate this from the user ID + the order ID
$amount = '10'; // Amount
$discount_type = 'percent'; // Type: fixed_cart, percent, fixed_product, percent_product
$coupon = array(
    'post_title' => $coupon_code,
    'post_content' => '',
    'post_status' => 'publish',
    'post_author' => 1,
    'post_type'     => 'shop_coupon'
);    
$new_coupon_id = wp_insert_post( $coupon );
// Add meta
update_post_meta( $new_coupon_id, 'discount_type', $discount_type );
update_post_meta( $new_coupon_id, 'coupon_amount', $amount );
update_post_meta( $new_coupon_id, 'individual_use', 'no' );
update_post_meta( $new_coupon_id, 'product_ids', '' );
update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );
update_post_meta( $new_coupon_id, 'usage_limit', '1' );
update_post_meta( $new_coupon_id, 'expiry_date', '' );
update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' );
update_post_meta( $new_coupon_id, 'free_shipping', 'no' );
And, then apply it to the order with a code like
if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code )))
    $woocommerce->show_messages();

The code returns for a boolean value. If it responses True, the discount is applied successfully, else a False value means the coupon is not applied yet. There could be various reasons for the failure and need to be reviewed thoroughly by an expert programmer.

 

5. Finding checkout page template

The default fields of a checkout page are often insufficient for the merchants to serve their customers rightly. To help the users customize or enter preferences for their orders, you may need to edit the checkout page and place additional options. For this, you may face difficulty in finding the checkout page. Let me help you in this regard.

wp-content/plugins/woocommerce/templates/checkout/form-checkout.php is the main file. You can get access to it and edit the code to achieve desired results. The checkout page comprises different pages. if you pursue to edit any specific step or page within the checkout process, here is the list of pages to start with.

  • cart-errors.php
  • form-billing.php
  • form-checkout.php
  • form-coupon.php
  • form-login.php
  • form-pay.php
  • form-shipping.php
  • review-order.php
  • thankyou.php

Be careful while altering while adding fields. Make sure the code you add is error free and written by an expert.

Conclusion

Management of a WooCommerce store is not as easy as it may seem to a person. Only an experienced and hard-working merchant knows what it takes to manage a WooCommerce web shop. if you are pursuing a startup and do not know the basics, you can seek guidance from the online tutorials or other useful content around the above. In the above points, we have tried to guide you maximum about the problems you may face with the cart along with effective solutions.

Comments

comments