• Skip to primary navigation
  • Skip to content

  • How To
  • Windows
  • Linux
  • Prestashop
  • WooCommerce
Home » woocommerce

woocommerce

Hide coupon on cart page only – WooCommerce

To hide coupon on cart page for WooCommerce add the following code in the functions.php file:

1
2
3
4
5
6
7
8
// hide coupon field on cart page only
function hide_coupon_field_on_cart( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_cart' );

Additionally, if you want to remove the coupon on the checkout page, add the following code in the functions.php file:

1
2
3
4
5
6
7
8
// hide coupon field on checkout page
function hide_coupon_field_on_checkout( $enabled ) {
if ( is_checkout() ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_checkout' );

 

Filed Under: How To, WooCommerce Tagged With: hide woocommerce coupon, woocommerce

How to increase WooCommerce page speed – wc-ajax=get_refreshed_fragments

The “wc-ajax=get_refreshed_fragments” is used by WooCommerce to update the cart when users go to a cached page. Since WooCommerce is a resource intensive plugin which may use lots of server resources to load all relevant styles and scripts, it make sense to dequeue all WooCommerce related stuff on the blog posts or home page. Basically, you will allow WooCommerce scripts to run on shop relevant pages, allowing all other pages to load faster.

Solution provided  by alenabdula on gist.github.com. Add the following code to your functions.php file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/** Dequeue both styles and scripts, Except Shop Pages*/
add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_styles_scripts', 99 );
function dequeue_woocommerce_styles_scripts() {
if ( function_exists( 'is_woocommerce' ) ) {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
# Styles
wp_dequeue_style( 'woocommerce-general' );
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
# Scripts
wp_dequeue_script( 'wc_price_slider' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
}
}
}

Other things you can try to increase speed

Stop Heartbeat API

Add this code to functions.php file of your theme.

1
2
3
4
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}

Note: stopping the heartbeat API will disable the auto save and revisions (you will have to manually Save Draft to save your content). Also, you will not see any real-time stats if any of your installed plugin uses the heartbeat API to update their content from the server.

Increase WP Memory

You should also increase WP memory to 256 MB. Add the following code to your wp-config.php file:

1
2
3
/** Memory Limit */
define('WP_MEMORY_LIMIT', '256M');
define( 'WP_MAX_MEMORY_LIMIT', '256M' );

 

Filed Under: WooCommerce Tagged With: how-to, woocommerce

WooCommerce: Automatically Complete all Orders

WooCommerce

By default, WooCommerce orders are saved as Processing. Only orders that contain “downloadable” products are automatically completed upon payment. In case you sell virtual products you may want to automatically complete all orders as they arrive, saving you a lot of time by not manually approve/complete orders.

There are some plugins available you can use to let WooCommerce process orders automatically if the they payment is complete. However, there is an easier way to do this by using a snippet. Just add the following code to the end of your functions.php file which is located in “wp-content/themes/your-theme-name/”, or  “wp-content/themes/your-child-theme-name/” if you are using a child theme:

1
2
3
4
5
6
7
8
9
/** Auto Complete all WooCommerce orders */
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
    if ( ! $order_id ) {
        return;
    }
    $order = wc_get_order( $order_id );
    $order->update_status( 'completed' );
}

The above method works only for online payments (PayPal and Credit cards gateway payments). If you are using BACS (direct bank transfer), Cheque or COD (cash on delivery) payment methods  you would need to implement a conditional code based on selected payment method – i.e. if the selected payment method IS NOT BACS, COD or Cheque then apply the above snippet to automatically complete order.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/** Auto Complete all WooCommerce orders */
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
    if ( ! $order_id ) {
        return;
    }
    $order = wc_get_order( $order_id );
// No status update for BACS, COD or Cheque payment methods
  if ( ( 'bacs' == get_post_meta($order->id, '_payment_method', true) ) || ( 'cod' == get_post_meta($order->id, '_payment_method', true) ) || ( 'cheque' == get_post_meta($order->id, '_payment_method', true) ) ) {
    return;
  }
// Update status for paid orders with all others payment methods
  else {
    $order->update_status( 'completed' );
  }
}

Using the above updated snippet the BACS, COD and Cheque payment methods will be ignored and keep their original status, and will automatically complete orders for paid orders only.

 

Filed Under: How To, WooCommerce Tagged With: woocommerce

  • Home
  • Disclaimer
  • Privacy Policy
  • Contact
  • My Account

© 2019 · Zecheru