Skip to content

Instantly share code, notes, and snippets.

@bentasm1
bentasm1 / functions.php
Last active August 12, 2023 21:09
Charge a $ amount, instead of a % for commission, or charge $ AND % for commission in WC Vendors
Add the following code to your themes functions.php file.
FIXED $ AMOUNT FOR COMMISSIONS:
Rather than paying a percentage of each sale, you may wish to pay a set dollar amount per sale.
To do this, change the commission percentage in your settings to "5". If you do that, you will
send out $5 in commissions per item sold, rather than 5%. Of course, use your own figures
and test before going live.
add_filter( 'wcv_commission_rate', 'my_wcv_custom_filter', 10, 3 );
function my_wcv_custom_filter( $commission, $product_id, $product_price ) {
@bentasm1
bentasm1 / Shortcode Examples
Last active July 26, 2023 14:52
WC Vendors Shortcodes
==== SHORTCODES FOR WC VENDORS FREE ONLY ====
WC Vendors Free Dashboard page - [wcv_vendor_dashboard]
WC Vendors Free Shop Settings page, normally a child page of the Dashboard - [wcv_shop_settings]
WC Vendors Free Orders page, normally a child page of the dashboard - [wcv_orders]
Directory of Vendors (To edit template, copy and modify ./templates/front/vendor-list.php)
[wcv_vendorslist] Accepts arguments of:
orderby='registered' (default)
order='ASC' (default)
per_page='12' (default)
@bentasm1
bentasm1 / functions.php
Last active November 28, 2022 22:15
WC Vendors - Stripe Gateway & Commissions - Tell admin in user edit if vendor connected to stripe
add_action('_wcv_admin_before_store_commission', 'custom_wcv_admin_before_store_commission');
function custom_wcv_admin_before_store_commission(){
$user_id = $_GET['user_id']; // On the WordPress user edit screen, this will get the user id of the account you are currently editing.
$key = get_user_meta( $user_id, '_stripe_connect_access_key', true );
if ( empty( $key ) ) {
echo '<h2>This vendor is NOT connected to Stripe.</h2>';
} else {
echo '<h2>This vendor is connected to Stripe. Yay!</h2>';
}
}
@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);
}
@bentasm1
bentasm1 / functions.php
Last active November 20, 2020 10:38
WC Vendors Pro - Advanced Custom Fields Support
/* - Courtesy of Ben Lumley - https://www.wcvendors.com/help/topic/howto-add-acf-fields-to-frontend-shop-edit/
*
* This will display + save any custom fields applicable to the vendor_shop in question. Second one displays the fields, you can adjust the action it’s attached to in order * to move the fields (see templates/dashboard/store-settings.php in the pro plugin for possible actions). You could also split and display different fields in different * places – see the docs for acf_form, you can select single/groups of fields.
* http://www.advancedcustomfields.com/resources/acf_form/
* Also possible via acf_form to alter the markup a bit to make it fit your theme.
*
* This code is not supported by WC Vendors, use at your own risk and at your own discretion.
*/
add_action('wcvendors_settings_after_shop_name', 'wcv_save_acf_fields');
@bentasm1
bentasm1 / functions.php
Last active May 30, 2020 15:50 — forked from digitalchild/functions.php
Add custom link to pro dashboard navigation tabs
/* WC Vendors Pro - Add a custom link to your Pro Dashboard navigation bar */
add_filter( 'wcv_pro_dashboard_urls', 'custom_menu_link' );
function custom_menu_link( $pages ) {
$pages[ 'custom_link' ] = array(
'slug' => 'http://yoursite.com/customlink/here', // Change this to whatever you like, it must be a full URL
'label' => __('My Custom Link', 'wcvendors-pro' ),
'actions' => array()
);
return $pages;
}
@bentasm1
bentasm1 / functions.php
Created November 12, 2015 17:16
WC Vendors Pro -- Change defaults for Stock Management / Quantity / Sold Individually
/* Credit to @criticalachievement */
// Changes the default value for manage stock checkbox to checked
add_filter( 'wcv_product_manage_stock', 'change_default_manage_stock' );
function change_default_manage_stock() {
$field['post_id'] = $post_id;
$field['id'] = '_manage_stock';
$field['wrapper_class'] = 'show_if_simple show_if_variable';
@bentasm1
bentasm1 / functions.php
Last active March 9, 2020 06:22
WC Vendors Pro -- Require a minimum, and a maximum price for vendors when adding/editing a product
/* WC Vendors Pro -- Require a minimum, and a maximum price for vendors when adding/editing a product */
add_filter( 'wcv_product_price', 'price_min_max' );
function price_min_max( $args ){
$args[ 'custom_attributes' ] = array(
'data-rules' => 'decimal|range[1,20]',
'data-error' => __( 'Price should be a number and between $1 and $20', 'wcvendors-pro' )
);
return $args;
}
@bentasm1
bentasm1 / functions.php
Last active August 7, 2018 23:13
WC Vendors Pro - Commission Rate depending on how much a product sells for
/* WC Vendors Pro -- No % for commission, just a tiered fee structure */
add_filter( 'wcv_commission_rate', 'my_wcv_commission_rate', 10, 5 );
function my_wcv_commission_rate( $commission, $product_id, $product_price, $order, $qty ) {
// First, reduce price to qty1 to do calculations
$product_price = $product_price / $qty;
// Second, run through the price and apply the right commission fee
if ( $product_price > 48.99 ) {
$commission_fee = 3.36;
@bentasm1
bentasm1 / functions.php
Last active July 2, 2018 11:48
Change Vendors to other stuff
/* WC Vendors - Change Apply to become a vendor? on registration pages */
add_filter( 'wcvendors_vendor_registration_checkbox', 'custom_wcvendors_vendor_registration_checkbox', 10, 1 );
function custom_wcvendors_vendor_registration_checkbox( $message ) {
$message = "Apply to become an Expert?";
return $message;
}
/* WC Vendors - Change Seller Info to Expert Details */
add_filter( 'wcvendors_seller_info_label', 'custom_wcvendors_seller_info_label', 10, 1 );
function custom_wcvendors_seller_info_label( $message ) {