These utilities are grouped into related files, for simpler copy & paste to your scripts.
A couple of helper functions to convert to & from A1 notation.
<?php | |
/** | |
* Plugin Name: WooCommerce Settings Tab Demo | |
* Plugin URI: https://gist.github.com/BFTrick/b5e3afa6f4f83ba2e54a | |
* Description: A plugin demonstrating how to add a WooCommerce settings tab. | |
* Author: Patrick Rauland | |
* Author URI: http://speakinginbytes.com/ | |
* Version: 1.0 | |
* | |
* This program is free software: you can redistribute it and/or modify |
/** | |
* Route single page to custom template | |
* | |
* @return string of path | |
*/ | |
function fr_route_template( $single_template ){ | |
// Put any conditional tag here. This one assumes you want to serve custom template for CPT titled "newsletter"'s single page | |
if( is_singular( 'newsletter' ) ){ |
// [Ref:][http://www.remicorson.com/mastering-woocommerce-products-custom-fields/] | |
/*=================================================================== | |
== FUNCTIONS FOR FREE PRODUCT & TOTAL PRODUCT | |
====================================================================*/ | |
/****************CUSTOM FIELD FOR CUSTOM GENERAL FIELD**************************************************/ | |
// Add Free Number Custom Field in Woocommerce | |
//Display Field |
<?php | |
/** | |
* @author Mirco Babini, SED Web Italia | |
* | |
* Contents: | |
* - reset payment method on 'add to cart' | |
* - add message to (customer) email per payment method | |
* - add payment method to email | |
* - remove product tabs | |
* - remove result count and default ordering (doesnt work?) |
<?php | |
// WooCommerce Shipping Calculated after Coupon | |
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'filter_shipping', 10, 2 ); | |
function filter_shipping( $is_available, $package ) { | |
if ( WC()->cart->prices_include_tax ) | |
$total = WC()->cart->cart_contents_total + array_sum( WC()->cart->taxes ); | |
else |
jQuery(document).ready(function ( $ ) { | |
$( 'button.load_customer_billing' ).off( 'click' ); | |
$( 'button.load_customer_billing' ).on( 'click', function() { | |
if ( window.confirm( woocommerce_admin_meta_boxes.load_billing ) ) { | |
// Get user ID to load data for | |
var user_id = $( '#customer_user' ).val(); | |
if ( ! user_id ) { | |
window.alert( woocommerce_admin_meta_boxes.no_customer_selected ); |
<?php | |
/** | |
* Add the field to order emails | |
**/ | |
add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys'); | |
function my_custom_checkout_field_order_meta_keys( $keys ) { | |
$keys[] = 'My Field 1'; | |
$keys[] = 'My Field 2'; | |
return $keys; |
<?php | |
// add custom column headers | |
function wc_csv_export_modify_column_headers( $column_headers ) { | |
$new_headers = array( | |
'column_1' => 'Column 1', | |
'column_2' => 'Column 2', | |
// add other column headers here in the format column_key => Column Name | |
); | |
<?php // only copy this line if needed! | |
/** | |
* Adds customer first and last name to admin new order email subject. | |
* | |
* @param string $subject email subject | |
* @param \WC_Order $order the order object for the email | |
* @return string updated subject | |
*/ |