Skip to content

Instantly share code, notes, and snippets.

View kloon's full-sized avatar

Gerhard Potgieter kloon

View GitHub Profile
@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 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 / 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 / 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 / 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] );
}
}
// Add to functions.php
/*===================================================
Created by sk from Renegade Empire with help
from these sources:
http://docs.woothemes.com/document/editing-product-data-tabs/
http://www.sean-barton.co.uk/2013/03/remove-woocommerce-20-reviews-tab/#.UYnWe7XfB6N
http://www.sean-barton.co.uk/2013/03/sb-add-woocommerce-tabs-wordpress-plugin/#.UYrYL7XfB6M
@kloon
kloon / woocommerce_products_sold_single_product.php
Last active December 9, 2017 14:30
WooCommerce display number of products sold on single product page
<?php
add_action( 'woocommerce_single_product_summary', 'wc_product_sold_count', 11 );
function wc_product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->id, 'total_sales', true );
echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}
?>
@kloon
kloon / woocommerce_product_enquiry_vendor.php
Last active October 25, 2016 10:08
WooCommerce Product Enquiry Form send enquiry to vendor
<?php
add_filter( 'product_enquiry_send_to', 'wc_product_enquiry_to_vendor', 10, 2 );
function wc_product_enquiry_to_vendor( $email, $product_id ) {
$vendors = get_product_vendors( $product_id );
if ( ! empty( $vendors ) ) {
$emails = array();
foreach( $vendors as $vendor ) {
foreach( $vendor->admins as $admin ) {
$emails[] = $admin->data->user_email;
}
@kloon
kloon / functions.php
Last active November 26, 2020 02:21
WooCommerce set tax exemption based on user role
<?php
add_filter( 'init', 'wc_tax_exempt_user_roles' );
function wc_tax_exempt_user_roles() {
if ( ! is_admin() ) {
global $woocommerce;
if ( current_user_can('wholesaler') || current_user_can('distributor') ) {
$woocommerce->customer->set_is_vat_exempt(true);
} else {
$woocommerce->customer->set_is_vat_exempt(false);
}
@kloon
kloon / functions.php
Created August 30, 2013 08:35
WooSlider Single Product Image slideshow - Replace the featured single product image with a WooSlider slideshow of images
<?php
add_filter( 'woocommerce_single_product_image_html', 'wc_product_image_slider' );
function wc_product_image_slider() {
return do_shortcode( '[wooslider slider_type="attachments"]' );
}
?>