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 March 12, 2013 11:59
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 February 28, 2013 08:37
WooCommerce redirect subscription add to cart to checkout page
<?php
add_filter('add_to_cart_redirect', 'custom_add_to_cart_redirect');
function custom_add_to_cart_redirect( $url ) {
$product_id = (int) $_REQUEST['add-to-cart'];
if ( class_exists( 'WC_Subscriptions_Product' ) ) {
if ( WC_Subscriptions_Product::is_subscription( $product_id ) ) {
return get_permalink(get_option( 'woocommerce_checkout_page_id' ) );
} else return $url;
} else return $url;
}
@kloon
kloon / functions.php
Last active July 5, 2023 10:05
WooCommerce add Delete Account button to My Account page This is very dangerous functionality and can cause your whole WordPress installation to break
<?php
// Delete Account Functionality
add_action( 'woocommerce_after_my_account', 'woo_delete_account_button' );
function woo_delete_account_button() {
?>
<a href="<?php echo add_query_arg( 'wc-api', 'wc-delete-account', home_url( '/' ) ) ?>" class="button">Delete Account</a>
<?php
}
add_action( 'woocommerce_api_' . strtolower( 'wc-delete-account' ), 'woo_handle_account_delete' );
@kloon
kloon / functions.php
Created February 14, 2013 07:28
WooCommerce Shelflife do not show sidebar on single product pages
<?php
remove_action( 'woo_main_after', 'woocommerce_get_sidebar', 10 );
add_action( 'woo_main_after', 'woo_custom_sidebar', 10 );
function woo_custom_sidebar() {
if ( ! is_product() ) {
woocommerce_get_sidebar();
}
}
remove_action( 'woocommerce_before_main_content', 'shelflife_before_content', 10 );
@kloon
kloon / functions.php
Created February 13, 2013 08:25
WooCommerce CC all emails
<?php
add_filter('woocommerce_email_headers', 'woo_cc_emails' );
function woo_cc_emails() {
return 'Bcc: youremail@yourdomain.com' . "\r\n";
}
?>
@kloon
kloon / functions.php
Created February 11, 2013 09:49
WooCommerce Canvas Move Cart to Top Nav
<?php
remove_action( 'woo_nav_inside', 'woo_add_nav_cart_link' );
add_filter( 'wp_nav_menu_items', 'woo_move_cart_to_top_nav', 10, 2 );
function woo_move_cart_to_top_nav( $items, $args ) {
global $woocommerce;
if ( $args->menu_id == 'top-nav' ) {
$items .= '<li><a class="cart-contents" href="'.esc_url( $woocommerce->cart->get_cart_url() ).'" title="'.esc_attr_e( 'View your shopping cart', 'woothemes' ).'">'.sprintf( _n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes' ), $woocommerce->cart->cart_contents_count ).' - '.$woocommerce->cart->get_cart_total().'</a></li>';
}
return $items;
@kloon
kloon / gist:4752925
Created February 11, 2013 05:54
Zues WordPress URL rewrites ( Working for WP MU )
#Zeus webserver version of basic Wordpress mod_rewrite rules
map path into SCRATCH:path from %{URL}
look for file at %{SCRATCH:path}
if exists then goto END
look for dir at %{SCRATCH:path}
if exists then goto END
##### FIX FOR LOGIN/FORGOTTEN PASSWORD/ADMIN ETC #####
match URL into $ with ^/wp-.*$
if matched then goto END
set URL = /index.php
@kloon
kloon / functions.php
Last active December 12, 2015 03:19
WooCommerce Mark Virtual Product Orders Completed
<?php
add_filter( 'woocommerce_payment_complete_order_status', 'virtual_order_payment_complete_order_status', 10, 2 );
function virtual_order_payment_complete_order_status( $order_status, $order_id ) {
$order = new WC_Order( $order_id );
if ( $order_status == 'processing' &&
( $order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed' ) ) {
$virtual_order = true;
@kloon
kloon / gist:4633463
Last active December 27, 2019 15:04
WooCommerce Disable Coupons on Sale Items
<?php
// Exclude coupons from being applied when products on sale
add_filter( 'woocommerce_coupon_is_valid', 'woocommerce_coupon_check_sale_items', 10, 2 );
function woocommerce_coupon_check_sale_items( $valid, $coupon ) {
global $woocommerce;
$valid_for_cart = $valid;
if (sizeof($woocommerce->cart->get_cart())>0) : foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) :
if ( function_exists( 'get_product') )
$product = get_product( $cart_item['product_id'] );
@kloon
kloon / gist:4604097
Created January 23, 2013 10:23
WooCommerce Custom Orderby
<?php
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
if( isset ( $_SESSION['orderby'] ) ) {
switch ( $_SESSION['orderby'] ) {
case 'sku_asc' :
$args['orderby'] = 'meta_value';
$args['order'] = 'asc';
$args['meta_key'] = '_sku';
break;