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 25, 2014 07:55
WooCommerce 2.1 Add confirm password option at checkout
<?php
// place the following code in your theme's functions.php file
// Add a second password field to the checkout page.
add_action( 'woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 1 );
function wc_add_confirm_password_checkout( $checkout ) {
if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) {
$checkout->checkout_fields['account']['account_password2'] = array(
'type' => 'password',
'label' => __( 'Confirm password', 'woocommerce' ),
'required' => true,
@kloon
kloon / functions.php
Last active September 8, 2015 06:32
WooCommerce 2.1 Grouped product prices, revert to WooCommerce 2.0 format
<?php
// Place in your theme's functions.php file
// Revert grouped product prices to WooCommerce 2.0 format
add_filter( 'woocommerce_grouped_price_html', 'wc_wc20_grouped_price_format', 10, 2 );
function wc_wc20_grouped_price_format( $price, $product ) {
$tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
$child_prices = array();
foreach ( $product->get_children() as $child_id ) {
$child_prices[] = get_post_meta( $child_id, '_price', true );
@kloon
kloon / functions.php
Last active September 8, 2015 06:32
WooCommerce 2.1 show trailing zeros
<?php
// Show trailing zeros on prices, default is to hide it.
add_filter( 'woocommerce_price_trim_zeros', 'wc_hide_trailing_zeros', 10, 1 );
function wc_hide_trailing_zeros( $trim ) {
// set to false to show trailing zeros
return false;
}
?>
@kloon
kloon / functions.php
Created February 18, 2014 13:09
WooCommerce add weight unit after price
<?php
// Add R xx.xx per KG
add_action( 'woocommerce_price_html', 'wc_custom_price', 10, 2 );
function wc_custom_price( $price, $product ) {
return sprintf( __( '%s per KG', 'woocommerce' ), woocommerce_price( $product->get_price() ) );
}
?>
@kloon
kloon / functions.php
Last active October 16, 2022 16:46
WooCommerce 2.1 variation price, revert to 2.0 format
/**
* Use WC 2.0 variable price format, now include sale price strikeout
*
* @param string $price
* @param object $product
* @return string
*/
function wc_wc20_variation_price_format( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
@kloon
kloon / functions.php
Created January 30, 2014 08:23
WooCommerce import Points & Rewards using Customer Order CSV Importer
<?php
add_action( 'woocommerce_api_points_rewards_custom_generator', 'wc_points_rewards_generate_custom_points' );
function wc_points_rewards_generate_custom_points() {
$customers = get_users( array(
'meta_key' => 'wc_points_balance'
) );
foreach ( $customers as $customer ) {
$points = get_user_meta( $customer->ID, 'wc_points_balance', true );
if ( $points > 0 ) {
if ( WC_Points_Rewards_Manager::increase_points( $customer->ID, $points, 'IMPORT' ) ) {
@kloon
kloon / functions.php
Created January 28, 2014 10:41
WooCommerce add product to cart on visit
<?php
// Place the following code in your theme's functions.php file
add_action( 'init', 'wc_add_product_to_cart_on_visit' );
function wc_add_product_to_cart_on_visit() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 64; // The ID of the product to add to cart
$found = false;
//check if product already in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
@kloon
kloon / functions.php
Last active December 18, 2021 18:55
WooCommerce Checkout Field Editor, add date range to datepicker field
<?php
// Add a date range to a datepicker field, replace #date with the id of the date field.
add_filter( 'wp_footer' , 'woo_add_checkout_field_date_range_limit' );
function woo_add_checkout_field_date_range_limit() {
if ( is_checkout() ) {
$js = 'jQuery( "#date" ).datepicker({ minDate: -5, maxDate: "+1M +10D" });';
// Check if WC 2.1+
if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
wc_enqueue_js( $js );
} else {
@kloon
kloon / functions.php
Created January 24, 2014 05:45
WooCommerce Remove Product Description from single product pages
<?php
// remove product description from single product pages
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_filter( 'woocommerce_product_tabs', 'wc_remove_description_tab', 11, 1 );
function wc_remove_description_tab( $tabs ) {
if ( isset( $tabs['description'] ) ) {
unset( $tabs['description'] );
}
}
?>
@kloon
kloon / functions.php
Created January 22, 2014 13:16
WooCommerce add order notes to completed emails
<?php
// Add an order notes section to customers' completed emails
add_action( 'woocommerce_email_after_order_table', 'wc_add_order_notes_to_completed_emails', 10, 1 );
function wc_add_order_notes_to_completed_emails( $order ) {
if ( 'completed' == $order->status ) {
echo '<h2>' . __( 'Order Notes', 'woocommerce' ) . '</h2>';
$order_notes = $order->get_customer_order_notes();
foreach ( $order_notes as $order_note ) {
echo '<p>' . $order_note->comment_content . '<p>';
}