This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() ) ); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ) ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'] ); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
} |