Skip to content

Instantly share code, notes, and snippets.

View michaeldoye's full-sized avatar

Michael Doye michaeldoye

View GitHub Profile
<?php
add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 2);
function add_bcc_all_emails($headers, $object) {
$headers = array();
$headers[] = 'Bcc: Name <me@email.com>';
$headers[] = 'Content-Type: text/html';
@michaeldoye
michaeldoye / functions.php
Last active August 29, 2015 14:23
Add custom fee to cart automatically
<?php
/**
* WooCommerce Extra Feature
*
* Add custom fee to cart automatically
*
*/
function woo_add_cart_fee() {
global $woocommerce;
/**
* Auto Complete all WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
@michaeldoye
michaeldoye / functions.php
Created June 26, 2015 21:18
Hide "Products" in WooCommerce breadcrumb
/*
* Hide "Products" in WooCommerce breadcrumb
*/
function woo_custom_filter_breadcrumbs_trail ( $trail ) {
foreach ( $trail as $k => $v ) {
if ( strtolower( strip_tags( $v ) ) == 'products' ) {
unset( $trail[$k] );
break;
}
}
@michaeldoye
michaeldoye / functions.php
Created June 26, 2015 21:22
Hide ALL Shipping option when free shipping is available
/**
* Hide ALL Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_all_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['free_shipping'] ) ) :
@michaeldoye
michaeldoye / functions.php
Last active August 29, 2015 14:23
Create a coupon programatically
$coupon_code = 'UNIQUECODE'; // Code
$amount = '10'; // Amount
$discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
$coupon = array(
'post_title' => $coupon_code,
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'shop_coupon'
@michaeldoye
michaeldoye / functions.php
Created June 26, 2015 21:26
Custom Add To Cart Messages
/**
* Custom Add To Cart Messages
**/
add_filter( 'woocommerce_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
global $woocommerce;
// Output success messages
if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
@michaeldoye
michaeldoye / functions.php
Created June 26, 2015 21:29
Display “product already in cart” instead of “add to cart” button
/**
* Change the add to cart text on single product pages
*/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text() {
global $woocommerce;
foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
@michaeldoye
michaeldoye / functions.php
Created June 26, 2015 21:32
Add custom field to edit address page
// add fields to edit address page
function woo_add_edit_address_fields( $fields ) {
$new_fields = array(
'date_of_birth' => array(
'label' => __( 'Date of birth', 'woocommerce' ),
'required' => false,
'class' => array( 'form-row' ),
),
);
@michaeldoye
michaeldoye / functions.php
Last active August 29, 2015 14:23
Add custom text to email based on payment method
//For this example we’ll add some helpful payment instructions to the email, based on the checkout payment type used
// https://www.sellwithwp.com/customizing-woocommerce-order-emails/
add_action( 'woocommerce_email_before_order_table', 'add_order_email_instructions', 10, 2 );
function add_order_email_instructions( $order, $sent_to_admin ) {
if ( ! $sent_to_admin ) {
if ( 'cod' == $order->payment_method ) {
// cash on delivery method