Skip to content

Instantly share code, notes, and snippets.

@bentasm1
bentasm1 / functions.php
Last active August 29, 2015 14:09 — forked from kloon/functions.php
Add text after product price
<?php
// Add R xx.xx per KG
add_action( 'woocommerce_price_html', 'wc_custom_price', 10, 2 );
function wc_custom_price( $price, $product ) {
return sprintf( __( '%s per KG', 'woocommerce' ), woocommerce_price( $product->get_price() ) );
}
?>
@bentasm1
bentasm1 / functions.php
Last active January 20, 2022 22:52 — forked from kloon/functions.php
Set WooCommerce Tax Exemption based on user role
<?php
add_filter( 'init', 'wc_tax_exempt_user_roles' );
function wc_tax_exempt_user_roles() {
if ( ! is_admin() ) {
global $woocommerce;
if ( current_user_can('wholesaler') || current_user_can('distributor') ) {
$woocommerce->customer->set_is_vat_exempt(true);
} else {
$woocommerce->customer->set_is_vat_exempt(false);
}
// Overwrite meta description for vendor pages
function overwrite_vendor_meta($desc) {
// Return the default value if we're not on a vendor shop page
if(!WCV_Vendors::is_vendor_page()) return $desc;
// Get the vendor description and return it
$vendor_shop = urldecode( get_query_var( 'vendor_shop' ) );
$vendor_id = WCV_Vendors::get_vendor_id( $vendor_shop );
$desc = get_user_meta( $vendor_id, 'pv_shop_description', true );
@bentasm1
bentasm1 / functions.php
Created October 10, 2015 15:24 — forked from digitalchild/functions.php
Change the Add Product URL on Pro Vendor dashboard
<?php
// Change the "Add Product" button url to the back end.
add_filter('wcv_add_product_url', 'new_add_product_url');
function new_add_product_url(){
return admin_url('post-new.php?post_type=product');
}
?>
@bentasm1
bentasm1 / product-edit.php
Created October 28, 2015 21:42 — forked from digitalchild/product-edit.php
WC Vendors Pro - Replace product descriptions with wordpress editor
<?php
// This code goes in the product-edit.php override template for wc-vendors pro
// Replace WCVendors_Pro_Product_Form::description( $object_id, $product_description );
// with
$product_description_args = array(
'editor_height' => 200,
'media_buttons' => true,
'teeny' => true,
@bentasm1
bentasm1 / functions.php
Created November 3, 2015 22:34 — forked from digitalchild/functions.php
Change dashboard date range
<?php
add_filter('wcv_dashboard_start_date', 'dashboard_start_date' );
function dashboard_start_date() {
return '-1 week';
}
@bentasm1
bentasm1 / functions.php
Created November 3, 2015 22:43 — forked from digitalchild/functions.php
Change the Pro Dashboard Date Range
<?php
// Change the start date
// from 1 year ago to 1 week ago
add_filter('wcv_dashboard_start_date', 'dashboard_start_date' );
function dashboard_start_date() {
return '-1 week';
}
// Change the end date
@bentasm1
bentasm1 / functions.php
Created November 7, 2015 18:54 — forked from digitalchild/functions.php
Only display the sold by if the product owner is a vendor
<?php
// Put this in your themes functions.php
// Remove all existing actions and filters
remove_action( 'woocommerce_after_shop_loop_item', array( 'WCV_Vendor_Shop', 'template_loop_sold_by'), 9, 2);
remove_filter( 'woocommerce_get_item_data', array( 'WCV_Vendor_Cart', 'sold_by' ), 10, 2 );
remove_action( 'woocommerce_product_meta_start', array( 'WCV_Vendor_Cart', 'sold_by_meta' ), 10, 2 );
remove_filter( 'woocommerce_order_product_title', array( 'WCV_Emails', 'show_vendor_in_email' ), 10, 2 );
remove_action( 'woocommerce_add_order_item_meta', array( 'WCV_Vendor_Shop', 'add_vendor_to_order_item_meta'), 10, 2 );
remove_action( 'woocommerce_after_shop_loop_item', array( $wcvendors_pro->wcvendors_pro_store_controller, 'loop_sold_by' ), 8 );
@bentasm1
bentasm1 / functions.php
Last active June 8, 2017 14:21 — forked from digitalchild/functions.php
Add a custom field to the store settings page for WCVendors Pro
This code adds a custom field to the Dashboard > Settings page for your vendors to
provide you extra bits of info you may need from them. Duplicate for each custom field you need,
renaming the meta keys and functions each time so they are not duplicated.
Part #1 - Theme functions.php file:
/* WC Vendors Pro - My Custom Field */
function store_bank_details( ){
if ( class_exists( 'WCVendors_Pro' ) ){
$key = '_wcv_custom_settings_bankname';
@bentasm1
bentasm1 / functions.php
Last active September 13, 2016 14:57 — forked from digitalchild/wcv_vendors_menu
WC Vendors Free & Pro Dynamic Vendor Menus
// Place this in your themes functions.php
// This will put the menu item in your primary menu. Change the theme location if you want to change which menu this goes in.
// Use the Free code for WC Vendors Free, use the Pro code for WC Vendors Pro
/* BEGIN WC Vendors Free */
add_filter( 'wp_nav_menu_items', 'wcv_vendors_menu', 10, 2 );
function wcv_vendors_menu ( $items, $args ) {
if ($args->theme_location == 'primary') {
$vendors = get_users( array( 'role' => 'vendor' ) );
$items .= '<li><a href="#">Vendors</a>';