View gist:2376300
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* goes in theme functions.php or a custom plugin | |
**/ | |
// add item to cart on visit | |
add_action( 'template_redirect', 'add_product_to_cart' ); | |
function add_product_to_cart() { | |
if ( ! is_admin() ) { | |
$product_id = 64; | |
$found = false; | |
//check if product already in cart |
View gist:3952058
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function product_count_shortcode( ) { | |
$count_posts = wp_count_posts( 'product' ); | |
return $count_posts->publish; | |
} | |
add_shortcode( 'product_count', 'product_count_shortcode' ); |
View gist:3972435
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Disable gateway based on country | |
function payment_gateway_disable_country( $available_gateways ) { | |
global $woocommerce; | |
if ( isset( $available_gateways['ccavenue'] ) && $woocommerce->customer->get_country() <> 'IN' ) { | |
unset( $available_gateways['ccavenue'] ); | |
} else if ( isset( $available_gateways['paypal'] ) && $woocommerce->customer->get_country() == 'IN' ) { | |
unset( $available_gateways['paypal'] ); | |
} | |
return $available_gateways; | |
} |
View gist:3993329
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change free price text | |
function custom_free_price( $price, $product ) { | |
return ''; | |
} | |
add_filter( 'woocommerce_free_sale_price_html', 'custom_free_price', 10, 2 ); | |
add_filter( 'woocommerce_free_price_html', 'custom_free_price', 10, 2 ); | |
add_filter( 'woocommerce_variable_free_price_html', 'custom_free_price', 10, 2 ); | |
add_filter( 'woocommerce_variable_free_sale_price_html', 'custom_free_price', 10, 2 ); |
View gist:4015657
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 ); | |
function add_loginout_link( $items, $args ) { | |
if (is_user_logged_in() && $args->theme_location == 'primary') { | |
$items .= '<li><a href="'. wp_logout_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) ) .'">Log Out</a></li>'; | |
} | |
elseif (!is_user_logged_in() && $args->theme_location == 'primary') { | |
$items .= '<li><a href="' . get_permalink( woocommerce_get_page_id( 'myaccount' ) ) . '">Log In</a></li>'; | |
} | |
return $items; | |
} |
View gist:4015723
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change empty price | |
function custom_empty_price( $price, $product ) { | |
return __( 'Call or Email for price', 'WooCommerce' ) ; | |
} | |
add_filter( 'woocommerce_variable_empty_price_html', 'custom_empty_price', 10, 2 ); | |
add_filter( 'woocommerce_empty_price_html', 'custom_empty_price', 10, 2 ); |
View gist:4015808
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Product Attributes shortcode | |
function custom_product_attr_shortcode( $atts ) { | |
if ( empty( $atts ) ) return; | |
if ( ! isset( $atts['id'] ) ) return; | |
$product = new WC_Product( $atts['id'] ); | |
$product->list_attributes(); | |
} | |
add_shortcode('product_attributes', 'custom_product_attr_shortcode'); |
View gist:4030229
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery( '.currency_switcher li a' ).each( function() { | |
jQuery( this ).parent().addClass( jQuery( this ).attr( 'data-currencycode' ) ); | |
}); |
View gist:4037251
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Display currency converter widget in non widget area | |
function custom_ccw_display_meta_end() { | |
$instance = array(); | |
$instance['title'] = 'Currency Converter'; | |
$instance['show_reset'] = 'yes'; // leave empty to disable | |
$instance['message'] = 'See the prices in your currency'; | |
$instance['currency_codes'] = "USD"."\n"."ZAR"."\n"."EUR"; // Must use \n between currencies and between "" | |
$args = array(); | |
the_widget( 'WooCommerce_Widget_Currency_Converter', $instance, $args); | |
} |
View gist:4040746
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SSL Logo | |
function custom_ssl_logo_head() { | |
$str = <<<EOD | |
<script language="javascript" type="text/javascript"> | |
//<![CDATA[ | |
var tl_loc0=(window.location.protocol == "https:")? "https://secure.comodo.net/trustlogo/javascript/trustlogo.js" : "http://www.trustlogo.com/trustlogo/javascript/trustlogo.js"; | |
document.writeln('<scr' + 'ipt language="JavaScript" src="'+tl_loc0+'" type="text\/javascript">' + '<\/scr' + 'ipt>'); | |
//]]> | |
</script> | |
EOD; |
OlderNewer