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 code below in your theme's functions.php file | |
add_filter( 'woocommerce_get_catalog_ordering_args', 'wc_get_catalog_ordering_args' ); | |
function wc_get_catalog_ordering_args( $args ) { | |
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); | |
if ( 'sales' == $orderby_value ) { | |
$args['orderby'] = 'meta_value_num'; | |
$args['order'] = 'DESC'; | |
$args['meta_key'] = 'total_sales'; | |
} |
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 to add the shipping method to all emails | |
add_action( 'woocommerce_email_after_order_table', 'wc_add_shipping_method_to_emails', 15, 2 ); | |
function wc_add_shipping_method_to_emails( $order, $is_admin_email ) { | |
echo '<p><strong>Shipping Method:</strong> ' . $order->get_shipping_method() . '</p>'; | |
} | |
// Place the following code in your theme's functions.php file to add the shipping methid to admin emails only | |
add_action( 'woocommerce_email_after_order_table', 'wc_add_shipping_method_to_admin_emails', 15, 2 ); | |
function wc_add_shipping_method_to_admin_emails( $order, $is_admin_email ) { |
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 once-of fee to the cart when certain items are in the cart | |
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); | |
function woocommerce_custom_surcharge() { | |
global $woocommerce; | |
$apply_fee = false; | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
$product_ids = array( 1, 2, 3, 4 ); // Coma separated list of product id's that must be in cart for fee to apply | |
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { |
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 Now: R12, Was: R15, Save 20% price for items on sale | |
add_action( 'woocommerce_sale_price_html', 'wc_custom_sale_price', 10, 2 ); | |
function wc_custom_sale_price( $price, $product ) { | |
$percentage = round( ( ( $product->regular_price - $product->get_price() ) / $product->regular_price ) * 100 ); | |
return sprintf( __( 'Now: %s, Was: %s, Save %s', 'woocommerce' ), woocommerce_price( $product->get_price() ), woocommerce_price( $product->regular_price ), $percentage . '%' ); | |
} | |
?> |
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 | |
// Limit the values customer can enter using measurement price calculator area ( LxW ) option | |
add_action( 'wp_head', 'limit_measurement_values', 99 ); | |
function limit_measurement_values() { | |
if ( is_product() ) { | |
?> | |
<script> | |
jQuery( document ).ready(function() { | |
jQuery( '#length_needed' ).change( function() { | |
if ( jQuery( this ).val() > 100 ) jQuery( this ).val( 100 ).keyup(); |
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>'; | |
} |
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 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 | |
// 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_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' ) ) { |