Skip to content

Instantly share code, notes, and snippets.

View woogist's full-sized avatar

WooCommerce.com Documentation woogist

View GitHub Profile
@woogist
woogist / wc-eu-vat-one-country.php
Created September 29, 2021 12:00
filter the countries where the VAT number field will show for
add_filter( 'woocommerce_eu_vat_number_country_codes', 'woo_custom_eu_vat_number_country_codes' );
function woo_custom_eu_vat_number_country_codes( $vat_countries ) {
// only show field for users in BE
return array( 'BE' );
}
add_filter( 'woocommerce_countries_base_postcode', create_function( '', 'return "80903";' ) );
add_filter( 'woocommerce_countries_base_city', create_function( '', 'return "COLORADO SPRINGS";' ) );
function wc_subscriptions_custom_price_string( $pricestring ) {
$pricestring = str_replace( 'every 3 months', 'per season', $pricestring );
$pricestring = str_replace( 'sign-up fee', 'initial payment', $pricestring );
return $pricestring;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string' );
function wc_edit_bookings_form_fields_order( $fields ) {
$duration = $fields['wc_bookings_field_duration'];
$persons = $fields['wc_bookings_field_persons'];
$resource = $fields['wc_bookings_field_resource'];
$date = $fields['wc_bookings_field_start_date'];
$new_fields = array(
'wc_bookings_field_start_date' => $date,
'wc_bookings_field_resource' => $resource,
'wc_bookings_field_duration' => $duration,
@woogist
woogist / gist:5541418
Created May 8, 2013 15:54
WooCommerce - Change Placeholder Image
/*
* goes in theme functions.php or a custom plugin. Replace the image filename/path with your own :)
*
**/
add_action( 'init', 'custom_fix_thumbnail' );
function custom_fix_thumbnail() {
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
@woogist
woogist / wc-admin-custom-order-fields-dynamic-options.php
Created April 1, 2014 17:58
An example of using the WooCommerce Admin Custom Order Fields 'wc_admin_custom_order_field_options' filter to return a dynamic set of options. In this sample we're pulling all WordPress terms, for the field which we have named "From Database". Options could be pulled from any other database/table, remote service, or anywhere! To use this code, c…
<?php
/*
* Returns a set of admin custom order field options from the database, rather
* than as configured by the admin
*/
add_filter( 'wc_admin_custom_order_field_options', function( $options, $field ) {
global $wpdb;
@woogist
woogist / gist:5692886
Last active January 23, 2021 17:56
Sample WooCommerce Points & Rewards 3rd Party Plugin Integration
<?php
// Add the action setting
add_filter( 'wc_points_rewards_action_settings', 'points_rewards_newsletter_action_settings' );
function points_rewards_newsletter_action_settings( $settings ) {
$settings[] = array(
'title' => __( 'Points earned for newsletter signup' ),
'desc_tip' => __( 'Enter the amount of points earned when a customer signs up for a newsletter via MailChimp.' ),
@woogist
woogist / functions.php
Last active December 19, 2020 01:25
Adds a top bar to Storefront, before the header
<?php
/**
* Adds a top bar to Storefront, before the header.
*/
function storefront_add_topbar() {
?>
<div id="topbar">
<div class="col-full">
<p>Your text here</p>
</div>
@woogist
woogist / storefront-add-featured-product-text-example.php
Created October 11, 2017 14:59
Documentation: Storefront Actions example: Adding content below the featured product title
@woogist
woogist / functions.php
Created November 25, 2014 08:33
Storefront top bar welcome message
<?php
/**
* Adds a top bar to Storefront, before the header.
*/
function storefront_add_topbar() {
global $current_user;
get_currentuserinfo();
if ( ! empty( $current_user->user_firstname ) ) {
$user = $current_user->user_firstname;