Skip to content

Instantly share code, notes, and snippets.

View bobwol's full-sized avatar
💭
coding as usual

bobwol

💭
coding as usual
View GitHub Profile
@bobwol
bobwol / wc-only-show-free-shipping.php
Created October 3, 2020 19:08 — forked from woogists/wc-only-show-free-shipping.php
[General Snippets][Hide other shipping methods when “Free Shipping” is available]
/**
* woocommerce_package_rates is a 2.1+ hook
*/
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
/**
* Hide shipping rates when free shipping is available
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
@bobwol
bobwol / wc-rename-country-example.php
Created October 3, 2020 19:08 — forked from woogists/wc-rename-country-example.php
[General Snippets] Rename a country in WooCommerce
/**
* Rename a country
*/
add_filter( 'woocommerce_countries', 'rename_ireland' );
function rename_ireland( $countries ) {
$countries['IE'] = 'Ireland';
return $countries;
}
@bobwol
bobwol / wc-change-number-of-related-products.php
Created October 3, 2020 19:08 — forked from woogists/wc-change-number-of-related-products.php
[Theming Snippets] Change number of related products output
@bobwol
bobwol / wc-change-number-of-upsells.php
Created October 3, 2020 19:08 — forked from woogists/wc-change-number-of-upsells.php
[Theming Snippets] Change number of upsells output
/**
* Change number of upsells output
*/
add_filter( 'woocommerce_upsell_display_args', 'wc_change_number_related_products', 20 );
function wc_change_number_related_products( $args ) {
$args['posts_per_page'] = 1;
$args['columns'] = 4; //change number of upsells here
return $args;
@bobwol
bobwol / wc-remove-related-products.php
Created October 3, 2020 19:08 — forked from woogists/wc-remove-related-products.php
[Theming Snippets] Remove related products output
@bobwol
bobwol / hide-all-shipping-keep-local-free.php
Created October 3, 2020 19:07 — forked from woogists/hide-all-shipping-keep-local-free.php
[General Snippets][Hide other shipping methods, but keep "Local pickup" when “Free Shipping” is available]
/**
* Hide shipping rates when free shipping is available, but keep "Local pickup"
* Updated to support WooCommerce 2.6 Shipping Zones
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
$new_rates = array();
foreach ( $rates as $rate_id => $rate ) {
// Only modify rates if free_shipping is present.
if ( 'free_shipping' === $rate->method_id ) {
@bobwol
bobwol / wc-custom-checkout-field.php
Created October 3, 2020 18:47 — forked from woogists/wc-custom-checkout-field.php
[Customizing checkout fields using actions and filters] Add a custom checkout field to WooCommerce.
/**
* Add the field to the checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';
woocommerce_form_field( 'my_field_name', array(
@bobwol
bobwol / reorder-checkout.php
Created October 3, 2020 18:46 — forked from cryptexvinci/reorder-checkout.php
re-order WooCommerce Checkout Fields
add_filter( 'woocommerce_checkout_fields', 'custom_move_checkout_fields' );
function custom_move_checkout_fields( $fields ) {
// Lets display the email first. You can move these around depending on your needs.
$billing_order = array(
"billing_email",
"billing_first_name",
"billing_last_name",
"billing_company",
@bobwol
bobwol / functions.php
Created October 3, 2020 18:19 — forked from ChromeOrange/functions.php
Change Single Product Tab Titles and Headings
<?php
/**
* Tab Title filters do not work with WooCommerce 1.6.5.1 or lower
* Please download this zip file http://cl.ly/2Y3S3D3M3C23 , extract the 3 files and copy them to :
* wp-content/themes/YOUR_THEME/woocommerce/single-product/tabs/
**/
add_filter ( 'woocommerce_product_description_tab_title', 'custom_product_description_tab_title' ) ;
function custom_product_description_tab_title() {
@bobwol
bobwol / remove_checkout_fields.php
Created September 30, 2020 14:17 — forked from cryptexvinci/remove_checkout_fields.php
Remove fields from WooCommerce checkout page.
add_filter( 'woocommerce_checkout_fields' , 'custom_remove_woo_checkout_fields' );
function custom_remove_woo_checkout_fields( $fields ) {
// remove billing fields
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);