Skip to content

Instantly share code, notes, and snippets.

View lmartins's full-sized avatar

Luis Martins lmartins

  • Goodwin Media, Multiweb
  • Portugal
View GitHub Profile
<?php
/**
* Get post image.
*/
function wds_get_post_image( $size = 'thumbnail' ) {
// Check for featured image
if ( has_post_thumbnail() ) {
the_post_thumbnail( $size );
@lmartins
lmartins / woo-cartcheckout.php
Last active August 29, 2015 14:10
Display WooCommerce Cart contents (only items quantity and total amount)
/**
* CART CONTENTS
* Mostra informação sobre conteúdo actual do carrinho
*/
add_action( 'genesis_site_title', 'mw_show_cart_contents' );
function mw_show_cart_contents()
{
global $woocommerce;
@lmartins
lmartins / post-types.php
Created November 27, 2014 20:02
Hides the preview button on lists and edit screens for custom post types
/**
* Esconder as opções de pré-visualização no front-end para Banners
* @return [type] [description]
*/
function posttype_admin_css() {
global $post_type;
$post_types = array(
/* set post types */
'banners',
);
@lmartins
lmartins / functions.php
Created November 25, 2014 22:42
If you sell digital products then you’re not shipping anything. You can autocomplete your orders using the following code:
/**
* Auto Complete all WooCommerce orders.
* http://docs.woothemes.com/document/automaticaaly-complete-orders/
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
global $woocommerce;
if ( ! $order_id ) {
@lmartins
lmartins / functions.php
Created November 25, 2014 22:42
Custom columns in WooCommerce Orders page
/**
* Custom Columns to Woo Orders Page
* @SEE: http://stackoverflow.com/questions/13683162/woocommerce-show-custom-column
*/
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION( $columns ) {
$new_columns = ( is_array( $columns ) ) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@lmartins
lmartins / functions.php
Created November 25, 2014 22:39
Skip the Cart in the checkout process
/**
* Skip the Cart
* @see: http://stackoverflow.com/questions/15592633/woocommerce-add-to-cart-button-redirect-to-checkout
*/
add_filter( 'add_to_cart_redirect', 'redirect_to_checkout' );
function redirect_to_checkout() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
@lmartins
lmartins / functions.php
Created November 25, 2014 22:38
Phone number not required in WooCommerce checkout form
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
function wc_npr_filter_phone( $address_fields ) {
$address_fields['billing_phone']['required'] = false;
return $address_fields;
}
@lmartins
lmartins / functions.php
Created November 25, 2014 22:36
Customize WooCommerce checkout fields order
add_filter( 'woocommerce_checkout_fields', 'reorder_woo_fields' );
function reorder_woo_fields( $fields ) {
//move these around in the order you'd like
$fields2['billing']['billing_first_name'] = $fields['billing']['billing_first_name'];
$fields2['billing']['billing_last_name'] = $fields['billing']['billing_last_name'];
$fields2['billing']['billing_company'] = $fields['billing']['billing_company'];
$fields2['billing']['billing_address_1'] = $fields['billing']['billing_address_1'];
$fields2['billing']['billing_address_2'] = $fields['billing']['billing_address_2'];
$fields2['billing']['billing_city'] = $fields['billing']['billing_city'];
@lmartins
lmartins / functions.php
Created November 25, 2014 22:35
Custom Add to Cart message and Continue to Shop link
add_filter( 'woocommerce_add_to_cart_message', 'woocommrece_custom_add_to_cart_message' );
function woocommrece_custom_add_to_cart_message() {
global $woocommerce;
// Output success messages
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {