Skip to content

Instantly share code, notes, and snippets.

View woogist's full-sized avatar

WooCommerce.com Documentation woogist

View GitHub Profile
@woogist
woogist / woo-product-custom-fields.php
Last active March 21, 2024 13:36
Display a product custom field within single product pages after the short description
<?php
// Display a product custom field within single product pages after the short description
function woocommerce_custom_field_example() {
if ( ! is_product() ) {
return;
}
@woogist
woogist / functions.php
Created December 24, 2014 11:17
Remove the Billing VAT field from the checkout form only for Wholesalers.
/**
* Remove the Billing VAT field from the checkout form only for Wholesalers.
*/
function custom_override_checkout_fields( $fields ) {
if ( ! current_user_can( 'wholesalers' ) && isset( $fields['billing']['billing_vat'] ) ) {
unset( $fields['billing']['billing_vat'] );
}
return $fields;
@woogist
woogist / woo_remove_product_warranty.php
Last active March 29, 2023 15:06
Remove the product warrant text from above the add to cart button on a product page
add_action( 'woocommerce_before_add_to_cart_button', 'woo_remove_product_warranty', 9);
function woo_remove_product_warranty() {
global $warranty_cart;
remove_action( 'woocommerce_before_add_to_cart_button', array( $warranty_cart, 'show_product_warranty' ) );
}
@woogist
woogist / gist:5934881
Created July 5, 2013 14:23
Automatically add product to cart on visit depending on cart total value
/*
* goes in theme functions.php or a custom plugin
**/
// add item to cart on visit depending on cart total value
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 2831;
$found = false;
@woogist
woogist / gist:5482370
Created April 29, 2013 15:30
Add CSS for social icons in Canvas v5.2 header
#header .social {float:right;}
#header .social a {
filter: alpha(opacity=@opacity * 100);
-moz-opacity: 0.8;
-khtml-opacity: 0.8;
opacity: 0.8;
-webkit-transition: all ease-in-out 0.2s;
-moz-transition: all ease-in-out 0.2s;
-o-transition: all ease-in-out 0.2s;
@woogist
woogist / gist:5482357
Created April 29, 2013 15:29
Add social Icons to Canvas v5.2 header php logic
add_filter( 'woo_header_inside', 'woo_custom_social_links', 10 );
function woo_custom_social_links () {
global $woo_options;
$settings = array(
'feed_url' => '',
'connect_rss' => '',
'connect_twitter' => '',
'connect_facebook' => '',
@woogist
woogist / functions.php
Last active February 1, 2023 11:09
Redirect to a custom page after login based on the user role
<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
@woogist
woogist / functions.php
Last active December 11, 2022 08:28
Create a vendor on account registration.
/**
* Create a vendor on account registration.
*
* @param int $customer_id
* @param array $new_customer_data
* @return boid
*/
function wc_create_vendor_on_registration( $customer_id, $new_customer_data ) {
$username = $new_customer_data['user_login'];
$email = $new_customer_data['user_email'];
@woogist
woogist / functions.php
Created June 8, 2015 13:07
WooCommerce Product Vendors: Add extra custom fields to vendor profiles
// Add fields to new vendor form
add_action( 'shop_vendor_add_form_fields', 'custom_add_vendor_fields', 2, 1 );
function custom_add_vendor_fields( $taxonomy ) {
?>
<div class="form-field">
<label for="vendor_website"><?php _e( 'Vendor website' ); ?></label>
<input type="text" name="vendor_data[website]" id="vendor_website" class="vendor_fields" /><br/>
<span class="description"><?php _e( 'The vendor\'s website.' ); ?></span>
</div>
<?php
@woogist
woogist / functions.php
Last active October 4, 2022 10:40
Apply different tax rates based on user role
<?php
/**
* Apply a different tax rate based on the user role.
*/
function wc_diff_rate_for_user( $tax_class, $product ) {
if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
$tax_class = 'Zero Rate';
}
return $tax_class;