Skip to content

Instantly share code, notes, and snippets.

View kloon's full-sized avatar

Gerhard Potgieter kloon

View GitHub Profile
@kloon
kloon / wc_hide_all_shipping_when_free_available.php
Created July 11, 2013 09:21
WooCommerce hide all shipping options when free shipping is available
<?php
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
function hide_standard_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['free_shipping'] ) ) {
$methods = $available_methods;
foreach( $methods as $key => $method ) {
if ( $key <> 'free_shipping' )
unset( $available_methods[$key] );
}
}
@kloon
kloon / woocommerce_customer_role_tax_exempt.php
Created July 8, 2013 11:52
WooCommerce Customer Tax Exempt based on role
<?php
// Place the following code in your theme's functions.php file and replace tax_exempt_role with the name of the role to apply to
add_action( 'init', 'woocommerce_customer_tax_exempt' );
function woocommerce_customer_tax_exempt() {
global $woocommerce;
if ( is_user_logged_in() ) {
$tax_exempt = current_user_can( 'tax_exempt_role');
$woocommerce->customer->set_is_vat_exempt( $tax_exempt );
}
}
@kloon
kloon / WooCommerce_free_shipping_user_role.php
Created June 21, 2013 13:28
WooCommerce Free Shipping based on user role
<?php
function get_user_role() {
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
return $user_role;
}
@kloon
kloon / functions.php
Last active December 16, 2015 13:19
WooCommerce eWAY Shared Payments Page Title
<?php
// Page Title, displayed as the title of the browser
add_filter( 'eway_shared_page_tite', 'woocommerce_eway_page_title' );
function woocommerce_eway_page_title() {
return __( 'My New Page Title', 'woocommerce' );
}
// Company Name, the name of the company the customer is buying from
add_filter( 'eway_shared_company_name', 'woocommerce_eway_company_name' );
@kloon
kloon / functions.php
Created April 10, 2013 12:58
WooCommerce Software Licences on My Account page
<?php
add_action( 'woocommerce_before_my_account', 'woocommerce_customer_licenses_my_account' );
function woocommerce_customer_licenses_my_account() {
global $wpdb;
$current_user = wp_get_current_user();
$licence_keys = $wpdb->get_results(
$wpdb->prepare(
"
SELECT * FROM {$wpdb->prefix}woocommerce_software_licences
WHERE activation_email = %s
@kloon
kloon / functions.php
Last active March 4, 2024 19:36
WooCommerce total order weight column on orders page
<?php
add_filter( 'manage_edit-shop_order_columns', 'woo_order_weight_column' );
function woo_order_weight_column( $columns ) {
$columns['total_weight'] = __( 'Weight', 'woocommerce' );
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'woo_custom_order_weight_column', 2 );
function woo_custom_order_weight_column( $column ) {
global $post, $woocommerce, $the_order;
@kloon
kloon / functions.php
Created March 27, 2013 07:06
WooCommerce backorder status on archive page
<?php
add_action( 'woocommerce_after_shop_loop_item', 'woocoomerce_archive_backorder', 6 );
function woocoomerce_archive_backorder(){
global $product;
if ( $product->backorders_require_notification() && $product->is_on_backorder( 1 ) )
echo '<p class="backorder_notification">' . __( 'Available on backorder', 'woocommerce' ) . '</p>';
}
?>
@kloon
kloon / functions.php
Created March 15, 2013 08:34
WooCommerce Product Up-Sells Shortcode
<?php
add_shortcode( 'product_upsells', 'wc_upsells_shortcode' );
function wc_upsells_shortcode( $atts ) {
extract( shortcode_atts( array(
'posts_per_page' => '-1',
'columns' => '2',
'orderby' => 'rand'
), $atts ) );
woocommerce_get_template( 'single-product/up-sells.php', array(
'posts_per_page' => $posts_per_page,
@kloon
kloon / functions.php
Created March 15, 2013 08:33
WooCommerce display brand image on single product page
<?php
add_action( 'woocommerce_before_single_product', 'wc_brand_image_single_product' );
function wc_brand_image_single_product() {
global $post;
$brands = wp_get_post_terms( $post->ID, 'product_brand' );
if ( $brands )
$brand = $brands[0];
if ( ! empty( $brand ) ) {
$thumbnail = get_brand_thumbnail_url( $brand->term_id );
$url = get_term_link( $brand->slug, 'product_brand' );
@kloon
kloon / functions.php
Created March 15, 2013 08:31
WooCommerce add PrettyPhoto/Lightbox to the checkout page for use
<?php
add_action( 'wp_enqueue_scripts', 'checkout_lightbox' );
function checkout_lightbox() {
global $woocommerce;
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
if ( is_checkout() ) {
wp_enqueue_script( 'prettyPhoto', $woocommerce->plugin_url() . '/assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array( 'jquery' ), $woocommerce->version, true );
wp_enqueue_script( 'prettyPhoto-init', $woocommerce->plugin_url() . '/assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array( 'jquery' ), $woocommerce->version, true );
wp_enqueue_style( 'woocommerce_prettyPhoto_css', $woocommerce->plugin_url() . '/assets/css/prettyPhoto.css' );
}