Categories
WooCommerce WordPress

Change “Add to Cart” text on single product page

<?php

function chetan_custom_cart_button_text() {

    return __( 'My Button Text', 'chetan' );

}

add_filter( 'add_to_cart_text', 'chetan_custom_cart_button_text' ); // WooCommerce < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'chetan_custom_cart_button_text' ); // WooCommerce 2.1 +
Categories
WooCommerce WordPress

WooCommerce – Automatically mark orders as “Complete”

<?php

function chetan_order_payment_complete_order_status( $order_status, $order_id ) {
  $order = new WC_Order( $order_id );
  
  if ( 'processing' === $order_status && ( 'on-hold' === $order->status || 'pending' === $order->status || 'failed' === $order->status ) ) {
    
    $is_virtual_order = null;
    if ( count( $order->get_items() ) > 0 ) {
      
      foreach( $order->get_items() as $item ) {
        
        if ( 'line_item' == $item['type'] ) {
          $_product = $order->get_product_from_item( $item );
          
          if ( ! $_product->is_virtual() ) {
            // once we've found one non-virtual product we know we're done, break out of the loop
            $is_virtual_order = false;
            break;
          } else {
            $is_virtual_order = true;
          }
          
        }
        
      }
      
    }
    
   if ( $is_virtual_order ) {
      return 'completed';
    }
    
  }

  return $order_status;
  
}

add_filter( 'woocommerce_payment_complete_order_status', 'chetan_order_payment_complete_order_status', 10, 2 );
Categories
WooCommerce WordPress

Remove Specific Product Tabs

<?php

function chet_remove_product_tabs( $tabs ) {

    unset( $tabs['reviews'] );
    
    return $tabs;

}

add_filter( 'woocommerce_product_tabs', 'chet_remove_product_tabs', 99 );
Categories
WooCommerce WordPress

WooCommerce – Update number of items in cart and total after Ajax

add_filter('add_to_cart_fragments', 'chet_tips_woocommerce_header_add_to_cart_fragment');

function chet_tips_woocommerce_header_add_to_cart_fragment( $fragments ) {
  global $woocommerce;

  ob_start();

  ?>
  <span class="cart-count"><?php echo $woocommerce->cart->cart_contents_count; ?></span>
  <?php

  $fragments['span.cart-count'] = ob_get_clean();

  return $fragments;

}
Categories
WooCommerce

How to Change the Login Logo URL in WordPress