Skip to content

Instantly share code, notes, and snippets.

Avatar

digitalchild digitalchild

View GitHub Profile
@digitalchild
digitalchild / functions.php
Created Nov 19, 2020
Limit cart and checkout to a single vendor stores products in WC Vendors Marketplace and WC Vendors Pro.
View functions.php
<?php
// Limit checkout to a single vendor store
add_action( 'woocommerce_add_to_cart_validation', 'limit_single_vendor_to_cart', 10, 3 );
function limit_single_vendor_to_cart( $valid, $product_id, $quantity ) {
$vendor_id = get_post_field( 'post_author', $product_id );
// loop through the cart to check each vendor id
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$cart_product_id = $cart_item[ 'product_id' ];
@digitalchild
digitalchild / gist:f7100f749f6118925952e75f74a6d803
Created Nov 9, 2020
Make all bank fields in WC Vendors Pro Settings required
View gist:f7100f749f6118925952e75f74a6d803
<?php
add_filter( 'wcv_vendor_bank_account_name', 'make_required' );
add_filter( 'wcv_vendor_bank_account_number', 'make_required' );
add_filter( 'wcv_vendor_bank_name', 'make_required' );
add_filter( 'wcv_vendor_bank_routing_number', 'make_required' );
add_filter( 'wcv_vendor_bank_routing_number', 'make_required' );
add_filter( 'wcv_vendor_bank_bic_swift', 'make_required' );
function make_required( $field ){
$field['custom_attributes'] = array( 'required' => '' );
@digitalchild
digitalchild / pro-vendor-list.php
Created Sep 16, 2020
Add address to the pro vendor list template
View pro-vendor-list.php
<?php
/**
* The Template for displaying a vendor in the vendor list shortcode
*
* Override this template by copying it to yourtheme/wc-vendors/front
*
* @package WCVendors_Pro
* @since 1.2.3
* @version 1.6.3
*/
@digitalchild
digitalchild / functions.php
Created Sep 16, 2020
Filter the vendor address on the vendor list page only.
View functions.php
<?php
// Add this to your themes functions.php and replace the page number with yours
// as this will then only filter the address on this page and not sidewide
add_filter( 'wcv_format_store_address_args', 'my_wcv_format_store_address', 11, 2 );
function my_wcv_format_store_address( $address_args, $vendor_id ) {
// Change this number to the page id of your vendor list page.
if ( is_page( '394') ){
unset( $address_args['address1']);
unset( $address_args['postcode']);
unset( $address_args['country']);
@digitalchild
digitalchild / functions.php
Created Sep 14, 2020
Set a max length for the store name with 2 custom messages for WC Vendors Pro
View functions.php
<?php
add_filter( 'wcv_vendor_store_name', 'wcv_vendor_store_name_limit' );
function wcv_vendor_store_name_limit( $field ){
$field['custom_attributes'] = array(
'required' => '',
'data-parsley-required-message' => __( 'Store Name is required', 'wcvendors-pro' ),
'max' => '7',
'data-parsley-max-message' => __( 'Store Name max length 7', 'wcvendors-pro' ),
);
@digitalchild
digitalchild / functions.php
Last active Aug 24, 2020
remove stock status from the WC Vendors Pro products status column
View functions.php
<?php
add_filter('wcv_product_row_status', 'product_row_status', 10, 6 );
function product_row_status( $string, $product_status, $product_type, $date, $stock_status_label, $product ){
$new_string =
sprintf(
'<span class="status %s">%s</span><br />
<span class="product_type %s">%s</span><br />
<span class="product_date">%s</span><br />',
@digitalchild
digitalchild / functions.php
Last active Aug 8, 2020
Add 16% VAT to vendors commission.
View functions.php
<?php
// Add 16% VAT to vendor commission
add_filter( 'wcv_commission_rate', 'my_wcv_commission_rate', 10, 5 );
function my_wcv_commission_rate( $commission, $product_id, $product_price, $order, $qty ) {
$vat_fee = 0.16;
$marketplace_split = $product_price - $commission;
$vat = $marketplace_split * $vat_fee;
$commission -= $vat;
@digitalchild
digitalchild / functions.php
Created Jul 22, 2020
Remove the sorting and results from the vendor store pages.
View functions.php
<?php
add_action( 'template_redirect', 'clean_up_vendor_store' );
function clean_up_vendor_store(){
if ( is_shop() || is_product() ){
global $post;
if ( WCV_Vendors::is_vendor_page() ) {
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );
@digitalchild
digitalchild / functions.php
Created Jul 16, 2020
Put the reviews somewhere else on the page
View functions.php
<?php
// Remove the reviews tab
add_filter( 'woocommerce_product_tabs', 'remove_reviews_tab' );
function remove_reviews_tab( $tabs ){
WC_Vendors::log( $tabs );
unset( $tabs['reviews'] );
return $tabs;
}
@digitalchild
digitalchild / functions.php
Created Jul 6, 2020
Make a social field required in WC Vendors settings form
View functions.php
// To make a field required for social media you will need to use the social settings id
// Hook with 'wcv_social_field_(socialfield id).
// In this example it is 'instagram'
add_filter( 'wcv_social_field_instagram', 'make_required' );
function make_required( $field ){
$field['custom_attributes'] = array( 'required' => '' );
return $field;
}
You can’t perform that action at this time.