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 February 13, 2013 08:25
WooCommerce CC all emails
<?php
add_filter('woocommerce_email_headers', 'woo_cc_emails' );
function woo_cc_emails() {
return 'Bcc: [email protected]' . "\r\n";
}
?>
@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
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 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
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 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' );
}
@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: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 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
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;