Skip to content

Instantly share code, notes, and snippets.

@sibinx7
Last active November 14, 2017 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sibinx7/871efdb838aff125ce3aeb84589d899c to your computer and use it in GitHub Desktop.
Save sibinx7/871efdb838aff125ce3aeb84589d899c to your computer and use it in GitHub Desktop.
Wordpress Tips

Enable FTP wordpress update and plugin

define('FS_METHOD', 'direct');

Wordpress useful plugins

  • WPSiteSync for Content

Website accessability test

WooCommerce - Update cart data while user add more

add_shortcode('header_cart_count', 'header_cart_count_fn');

function header_cart_count_fn(){
  global $woocommerce;
  $output = '<a class="cart-customlocation" href="'.$woocommerce->cart->get_cart_url().'"><span class="fa fa-shopping-cart"></span>&nbsp;'.sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count).' -  '.$woocommerce->cart->get_cart_total().'</a>';
  return $output;
}

// Filter
add_filter('woocommerce_add_to_cart_fragments', function($fragments){
  global $woocommerce;
  ob_start();
  $output = '<a class="cart-customlocation" href="'.$woocommerce->cart->get_cart_url().'">
    <span class="fa fa-shopping-cart"><span>&nbsp;'.sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count).' - '.$woocommerce->cart->get_cart_total().'</a>';
  echo $output;
  $fragments['a.cart-customlocation'] = ob_get_clean();
  return $fragments;
});

Setup post data fpr any loop

setup_postdata( $post ); 
// Reference: https://codex.wordpress.org/Function_Reference/setup_postdata
// $post variable along with the setup_postdata()

Useful Wordpress Conditions

  • post_type_exists : Check post type

Useful Software/Tools

API Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment