Skip to content

Instantly share code, notes, and snippets.

@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
Created June 14, 2016 00:07 — forked from digitalchild/functions.php
Force stock qty to 1 with no backorders
<?php
add_action( 'wcv_save_product_meta', 'wcv_custom_stock_opts' );
function wcv_custom_stock_opts( $post_id ) {
update_post_meta( $post_id, '_manage_stock', 'yes' );
update_post_meta( $post_id, '_backorders', 'no' );
wc_update_product_stock( $post_id, wc_stock_amount( 1 ) );
}
@bentasm1
bentasm1 / functions.php
Last active December 1, 2017 01:23 — forked from digitalchild/functions.php
WC Vendors Pro - Add new tabs to Pro Dashboard Navigation
/* WC Vendors Pro - Add some new page links to the Pro Dashboard */
function new_dashboard_pages( $pages ){
$pages[] = array( 'label' => 'New Link', 'slug' => 'http://mysomelink.com' ); // Add stuff here
return $pages;
}
add_filter( 'wcv_pro_dashboard_urls', 'new_dashboard_pages' );
@bentasm1
bentasm1 / functions.php
Created May 27, 2016 19:36
WC Vendors - Redirect even from wp-login.php for the role vendor
/* WC Vendors - Redirect even from wp-login.php for the role vendor */
add_action( 'admin_init', 'wcvendors_wplogin_redirect' );
function wcvendors_wplogin_redirect() {
if ( ! defined( 'DOING_AJAX' ) ) {
$current_user = wp_get_current_user();
$role_name = $current_user->roles[0];
if ( 'vendor' === $role_name ) {
wp_redirect( 'http://yoursite.com/dashboard' );
} // if $role_name
@bentasm1
bentasm1 / functions.php
Created May 16, 2016 00:46
WC Vendors - Show vendors products in BuddyPress
/* Code by Fervous
* WC Vendors - Shows a "My Products" tab in BuddyPress and then the vendors products in that tab
*/
function my_bp_nav_adder() {
if (class_exists('WC_Vendors')) {
$wcv_profile_id = bp_displayed_user_id();
$wcv_profile_info = get_userdata( bp_displayed_user_id() );
if ( $wcv_profile_info->roles[0] == "vendor" ) {
@bentasm1
bentasm1 / functions.php
Created May 11, 2016 21:50 — forked from digitalchild/functions.php
WC Vendors Pro - Remove shipping panel from single product page
/* WC Vendors Pro - Remove shipping panel from single product page */
remove_action( 'woocommerce_product_tabs', array( $wcvendors_pro->wcvendors_pro_shipping_controller, 'shipping_panel_tab'), 11, 2 );
remove_action( 'woocommerce_product_meta_start', array( $wcvendors_pro->wcvendors_pro_vendor_controller, 'product_ships_from'), 9 );
@bentasm1
bentasm1 / functions.php
Last active January 12, 2017 16:30
WC Vendors Pro - Cart/Checkout Filter
/* WC Vendors Pro - Cart/Checkout Filter
* This is just an example of the WooCommerce checkout process and cart pages to "check" something and display an error of some
* sort. This code does nothing as it is, you'd have to write it inside the custom_checkout_filter function. Some
* notes are there to give you an idea on how to get data from the cart, and the WooCommerce notices function that
* shows a pretty box with a message. Have fun.
*/
add_action( 'woocommerce_checkout_process', 'custom_checkout_filter' );
add_action( 'woocommerce_before_cart' , 'custom_checkout_filter' );
function custom_checkout_filter() {
@bentasm1
bentasm1 / functions.php
Last active September 3, 2016 03:45
WC Vendors Pro Bank & IBAN Details
/* WC Vendors Pro - My Custom Bank Fields */
function store_bank_details( ){
if ( class_exists( 'WCVendors_Pro' ) ){
$key = '_wcv_custom_settings_bankname';
$value = get_user_meta( get_current_user_id(), $key, true );
// Bank Name
WCVendors_Pro_Form_Helper::input( array(
'id' => $key,
'label' => __( 'Banküberweisung als Auszahlungs Methode Ihres Provision verwenden', 'wcvendors-pro' ),
'placeholder' => __( 'Bank Name', 'wcvendors-pro' ),
@bentasm1
bentasm1 / functions.php
Created April 25, 2016 20:54
WC Vendors Pro - Additional Information on Ships From section
/* WC Vendors Pro - Custom "Ships From" code provided by @pronet
* https://www.wcvendors.com/help/topic/custom-ships-from-how-to/
* Say you want to show more detailed location information under single product view “Ships From” section.
* This will show in addition the city and state/province.
*/
function custom_ships_from(){
global $post;
$vendor_id = WCV_Vendors::get_vendor_from_product( $post->ID );
$town = get_user_meta( $vendor_id, '_wcv_store_city', true );
$county = get_user_meta( $vendor_id, '_wcv_store_state', true );
@bentasm1
bentasm1 / gist:cfc68661540d9f15de9fb9aed65db3ec
Created April 25, 2016 18:58
WC Vendors Pro - Add/edit product form change title & description to something else
The same type of code can be used for every field, these
two examples change the Product Title and Product Description
text to something else on the add/edit product form. Goes in
your themes functions.php file as always. ;)
add_filter('wcv_product_title', 'custom_wcv_product_title');
function custom_wcv_product_title( $args ){
$args['label'] = 'New Product Name Label';
return $args;
}