Skip to content

Instantly share code, notes, and snippets.

View tommyshellberg's full-sized avatar

Thomas Shellberg tommyshellberg

View GitHub Profile
@tommyshellberg
tommyshellberg / woocommerce-xero-account-code-override-snippet.php
Last active January 12, 2024 11:36
WooCommerce Xero Override Line Item Account Code By SKU
add_filter('woocommerce_xero_line_item_account_code', 'wc_custom_xero_account_code', 10, 2);
function wc_custom_xero_account_code($account_code, $line_item) {
// $line_item->get_item_code() returns the SKU of the line item.
if( $line_item->get_item_code() == 'ACME') {
return '460';
}
return $account_code;
}
@tommyshellberg
tommyshellberg / monthly-sales-custom-shortcode
Created June 11, 2018 13:06
WooCommerce - display the last 30 days of sales using shortcode
/**
* Monthly Sales Custom Shortcode
*/
add_shortcode( 'display_monthly_sales', 'print_monthly_sales_frontend' );
function print_monthly_sales_frontend() {
global $woocommerce, $wpdb, $product;
include_once($woocommerce->plugin_path() . '/includes/admin/reports/class-wc-admin-report.php');
// WooCommerce Admin Report
@tommyshellberg
tommyshellberg / wc-stripe-sofort-testing-snippet.php
Last active May 28, 2019 13:38
WooCommerce Stripe - Test a successful payment with SOFORT
add_filter('wc_stripe_sofort_source', 'add_testing_details_sofort', 10, 2);
function add_testing_details_sofort($post_data, $order) {
$post_data['owner']->name = 'succeeding_charge';
return $post_data;
}
@tommyshellberg
tommyshellberg / PR-Stripe-Snippet.php
Created April 15, 2019 15:22
WooCommerce Stripe gateway - Add Puerto Rico to allowable Stripe countries
<?php
add_filter('wc_stripe_supported_countries', 'wc_stripe_add_puerto_rico');
function wc_stripe_add_puerto_rico($countries) {
$countries[] = 'PR';
return $countries;
}
@tommyshellberg
tommyshellberg / functions.php
Created August 8, 2014 07:55
Change the Woocommerce Bookings display price to an amount per person
//Place in your theme's functions.php file
function custom_booking_price( $price, $product ) {
$target_product_types = array(
'booking'
);
if ( in_array ( $product->product_type, $target_product_types ) ) {
// if variable product change price output
$price = '';
$price .= woocommerce_price($product->get_price()) . ' per person';
@tommyshellberg
tommyshellberg / gist:bec88c936f387dfd3396ae92dde3e1dc
Created June 6, 2018 14:05
WooCommerce - Always send Purchase Note to both Customer and Admin
add_filter ('woocommerce_email_order_items_args', 'send_purchase_note_to_everyone');
function send_purchase_note_to_everyone( $args ) {
$args['show_purchase_note'] = true;
return $args;
}
@tommyshellberg
tommyshellberg / gist:aafec8ff631b2a938ba2829241ae7add
Created September 5, 2018 15:49
delete meta keys associated with WC Bookings if the products are missing(avoids fatal errors)
add_action('wp', 'delete_meta_bookings_no_products');
function delete_meta_bookings_no_products() {
$booking_ids = get_posts( array(
'numberposts' => 100000,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'wc_booking',
'post_status' => get_wc_booking_statuses(),
@tommyshellberg
tommyshellberg / style.css
Created January 29, 2016 17:27
Remove white frame Artificer product
ul.products li.product .img-wrap {
background: transparent;
-webkit-box-shadow: none;
-moz-box-shadow:none;
box-shadow: none;
}
ul.products li.product:hover .img-wrap {
background: transparent;
-webkit-box-shadow: none;
@tommyshellberg
tommyshellberg / gist:95b6ce8fcebc09236cdd
Created April 3, 2015 02:29
Append the WooCommerce Product Price with ' per hour' string
add_filter( 'woocommerce_get_price_html', 'custom_price_string', 100, 2 );
function custom_price_string( $price, $product ){
return $price . ' per hour';
}