Tweaks

1.Tweaks Overview #

WCFM Dashboard is most flexible one, you may change anything as per your requirement very easily. Now if we create setting option for all these then it will be a painful job for you to find out the right one for your purpose.

We have kept possibilities to tweak those easily by adding 1-2 lines of code. You may add those codes in two ways –

  1. Add codes at your child theme’s functions.php
  2. Install code snippet (https://wordpress.org/plugins/code-snippets/) plugin and add using this

Find below, some of the most popular tweaks people looking for!

Yes No

2.Products #

2.1.New Product Notification #

Well, Admin receive new Product email only if “Product Approval” enabled.
 
If it’s disabled then Admin does not receive email for All new products added by vendors.
 
But, if you really want to this email then add this line –
 
add_filter( 'wcfm_is_allow_new_product_notification_email', '__return_true' );
Yes No

2.2.Set Attributes Required #

By default product attributes are not required when you are adding products, but you may add this restriction by adding this code –

add_filter( 'wcfm_product_custom_attributes', function( $taxonomy_fields, $att_taxonomy ) {
if( isset( $taxonomy_fields[$att_taxonomy] ) && isset( $taxonomy_fields[$att_taxonomy]['options'] ) ) {
if( isset( $taxonomy_fields[$att_taxonomy]['options']['is_active'] ) ) {
$taxonomy_fields[$att_taxonomy]['options']['is_active']['custom_attributes'] = array( 'required' => 1, 'required_message' => 'Attributes are required' );
}
if( isset( $taxonomy_fields[$att_taxonomy]['options']['value'] ) ) {
$taxonomy_fields[$att_taxonomy]['options']['value']['custom_attributes'] = array( 'required' => 1, 'required_message' => 'Attributes are required' );
}
}
return $taxonomy_fields;
}, 50, 2);

Yes No

3.Vendor #

3.1.Restrict Add Product without Payment Setting #

You may restrict vendor’s “Add Product” permission if they not yet setup their payment setting –

add_filter( 'wcfm_is_allow_pm_add_products', function( $is_allow ) {
global $wp;
if( wcfm_is_vendor() ) {
$vendor_id = apply_filters( 'wcfm_current_vendor_id', get_current_user_id() );
$vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
$payment_mode = isset( $vendor_data['payment']['method'] ) ? esc_attr( $vendor_data['payment']['method'] ) : '' ;
$paypal_email = isset( $vendor_data['payment']['paypal']['email'] ) ? esc_attr( $vendor_data['payment']['paypal']['email'] ) : '' ;
$stripe_user_id = get_user_meta( $vendor_id, 'stripe_user_id', true );
if( !$payment_mode || ( ( $payment_mode == 'stripe' ) && !$stripe_user_id ) || ( ( $payment_mode == 'paypal' ) && !$paypal_email ) ) {
if( isset( $wp->query_vars['wcfm-products-manage'] ) ) {
wcfm_restriction_message_show( __( "Payment account not yet setup!", "wc-fronend-manager" ), false, true );
}
$is_allow = false;
}
}
return $is_allow;
}, 750 );

Yes No

3.2.Restrict Add Product without Shipping Setting #

You may restrict vendor’s “Add Product” permission if they not yet setup their shipping setting –

add_filter( 'wcfm_is_allow_pm_add_products', function( $is_allow ) {
global $wp, $WCFM;
if( $is_allow && function_exists( 'wcfm_is_vendor' ) && wcfm_is_vendor() ) {
$vendor_id = apply_filters( 'wcfm_current_vendor_id', get_current_user_id() );
$wcfmmp_shipping = get_user_meta( $vendor_id, '_wcfmmp_shipping', true );
$shipping_type = isset($wcfmmp_shipping['_wcfmmp_user_shipping_type'])? $wcfmmp_shipping['_wcfmmp_user_shipping_type'] : '';
$wcfmmp_shipping_by_country = get_user_meta( $vendor_id, '_wcfmmp_shipping_by_country', true );
$wcfmmp_country_weight_rates = get_user_meta( $vendor_id, '_wcfmmp_country_weight_rates', true );
$vendor_all_shipping_zones = wcfmmp_get_shipping_zone( '', $vendor_id );
if( !$wcfmmp_shipping || ( $wcfmmp_shipping && empty( $shipping_type ) ) || ( $wcfmmp_shipping && $shipping_type && ( $shipping_type == 'by_country' ) && empty( $wcfmmp_shipping_by_country ) ) || ( $wcfmmp_shipping && $shipping_type && ( $shipping_type == 'by_weight' ) && empty( $wcfmmp_country_weight_rates ) ) || ( $wcfmmp_shipping && $shipping_type && ( $shipping_type == 'by_zone' ) && empty( $vendor_all_shipping_zones ) ) ) {
$is_allow = false;
if( isset( $wp->query_vars['wcfm-products-manage'] ) ) {
wcfm_restriction_message_show( __( "Please setup your store shipping before to add product!", "wc-fronend-manager" ), false, true );
}
}
}
return $is_allow;
}, 60 );

Yes No

3.3.Restrict Add Product without Policy Setting #

You may restrict vendor’s “Add Product” permission if they not yet setup their store policy setting –

add_filter( 'wcfm_is_allow_pm_add_products', function( $is_allow ) {
global $wp;
if( wcfm_is_vendor() ) {
$vendor_id = apply_filters( 'wcfm_current_vendor_id', get_current_user_id() );
$wcfm_policy_vendor_options = (array) wcfm_get_user_meta( $vendor_id, 'wcfm_policy_vendor_options', true );
$_wcfm_vendor_shipping_policy = !empty( $wcfm_policy_vendor_options['shipping_policy'] ) ? $wcfm_policy_vendor_options['shipping_policy'] : '';
$_wcfm_vendor_refund_policy = !empty( $wcfm_policy_vendor_options['refund_policy'] ) ? $wcfm_policy_vendor_options['refund_policy'] : '';
$_wcfm_vendor_cancellation_policy = !empty( $wcfm_policy_vendor_options['cancellation_policy'] ) ? $wcfm_policy_vendor_options['cancellation_policy'] : '';
if( !$_wcfm_vendor_shipping_policy || !$_wcfm_vendor_refund_policy || !$_wcfm_vendor_cancellation_policy ) {
if( isset( $wp->query_vars['wcfm-products-manage'] ) ) {
wcfm_restriction_message_show( __( "Store policy not yet setup!", "wc-fronend-manager" ), false, true );
}
$is_allow = false;
}
}
return $is_allow;
}, 750 );

Yes No

4.Orders #

4.1.Order Status with Label #

WCFM Order listing page by default shows order status by icon. But you may change this and show status as icon+text as well.

You have to use this code snippet –

add_filter( 'wcfm_order_status_display', function( $label, $the_order ) {
$label .= '<br />' . wc_get_order_status_name( $the_order->get_status() );
return $label;
}, 50, 2 );

Hence it will look like this –

Yes No

4.2.Single Vendor Checkout #

You may use this code to restrict “one vendor’s products” checkout at a time.

add_action( 'woocommerce_add_to_cart_validation', function( $is_allow, $product_id, $quantity ) {
$product = get_post( $product_id );
$product_author = $product->post_author;
//Iterating through each cart item
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$cart_product_id = $cart_item['product_id'];
$cart_product = get_post( $cart_product_id );
$cart_product_author = $cart_product->post_author;
if( $cart_product_author != $product_author ) {
$is_allow = false;
break;
}
}
if( !$is_allow ){
// We display an error message
wc_clear_notices();
wc_add_notice( __( "Well, you already have some item in your cart. First checkout with those and then purchase other items!", "wcfm" ), 'error' );
}
return $is_allow;
}, 50, 3 );

Yes No

4.3.Vendor Order Threshold Amount #

This code will help to add “Minimum Order Amount” threshold for a vendor. Vendors’ will able to set this amount from their setting panel.

If customer will not match this threshold they will see a warning message at cart page.

add_action( 'end_wcfm_vendor_settings', function( $vendor_id ) {
global $WCFM, $WCFMmp;
$wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
?>
<div class="page_collapsible" id="wcfm_settings_form_min_order_amount_head">
<label class="wcfmfa fa-cart-plus"></label>
<?php _e('Min Order Amount', 'wc-frontend-manager'); ?><span></span>
</div>
<div class="wcfm-container">
<div id="wcfm_settings_form_vendor_invoice_expander" class="wcfm-content">
<?php
$WCFM->wcfm_fields->wcfm_generate_form_field( array(
"_wcfm_min_order_amt" => array('label' => __('Minimum Amount', 'wc-frontend-manager'), 'type' => 'number', 'class' => 'wcfm-text wcfm_non_negative_input wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_min_order_amt ),
) );
?>
</div>
</div>
<div class="wcfm_clearfix"></div>
<?php
}, 500 );
add_filter( 'wcfm_marketplace_settings_fields_general', function( $setting_fields, $vendor_id ) {
if( !wcfm_is_vendor() ) {
$wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
$wcfm_min_order_amt_field = array(
"_wcfm_min_order_amt" => array('label' => __('Minimum Amount', 'wc-frontend-manager'), 'type' => 'number', 'class' => 'wcfm-text wcfm_non_negative_input wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_min_order_amt ),
);
$setting_fields = array_merge( $wcfm_min_order_amt_field, $setting_fields );
}
return $setting_fields;
}, 50, 2 );
add_action( 'woocommerce_single_product_summary', function() {
global $WCFM, $WCFMmp, $post;
$vendor_id = 0;
$product_id = 0;
if( is_product() && $post && is_object( $post ) ) {
$product_id = $post->ID;
}
if( !$product_id ) return;
$vendor_id = wcfm_get_vendor_id_by_post( $product_id );
if( !$vendor_id ) return;
$wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
if( !$wcfm_min_order_amt ) return;
echo '<div class="wcfm_clearfix"></div><div class="wcfmmp_shipment_processing_display">'. __( 'Minimum order amount should be ', 'wc-multivendor-marketplace' ) . ' ' . wc_price( $wcfm_min_order_amt ) .'</div><div class="wcfm_clearfix"></div>';
}, 35 );
add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
global $WCFM, $WCFMmp;
if( isset( $wcfm_settings_form['_wcfm_min_order_amt'] ) ) {
$wcfm_min_order_amt = $wcfm_settings_form['_wcfm_min_order_amt'];
update_user_meta( $vendor_id, '_wcfm_min_order_amt', $wcfm_min_order_amt );
}
}, 500, 2 );
add_action( 'woocommerce_check_cart_items', function() {
global $WCFM, $WCFMmp;
$return = true;
if( is_cart() || is_checkout() ) {
$vendor_wise_cart_total = array();
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$cart_product_id = $cart_item['product_id'];
$cart_product = get_post( $cart_product_id );
if( !isset( $vendor_wise_cart_total[$cart_product->post_author] ) ) $vendor_wise_cart_total[$cart_product->post_author] = 0;
$vendor_wise_cart_total[$cart_product->post_author] += $cart_item['line_total'];
}
if( !empty( $vendor_wise_cart_total ) ) {
foreach( $vendor_wise_cart_total as $vendor_id => $cart_total ) {
if( wcfm_is_vendor( $vendor_id ) ) {
$wcfm_min_order_amt = get_user_meta( $vendor_id, '_wcfm_min_order_amt', true );
if( $wcfm_min_order_amt && ( $wcfm_min_order_amt > $cart_total ) ) {
wc_clear_notices();
$vendor_label = wcfm_get_vendor_store( $vendor_id ) . ' ' . apply_filters( 'wcfm_sold_by_label', $vendor_id, __( 'Store', 'wc-frontend-manager' ) );
wc_add_notice( sprintf( __( "%s minimum order amount should be %s, please add few more items from this store!", "wc-frontend-manager" ), $vendor_label, wc_price( $wcfm_min_order_amt ) ), 'error' );
$return = false;
break;
}
}
}
}
}
return $return;
}, 1000 );

Yes No

5.Commission #

5.1.Estimated Commission Show #

This will show estimated commission for a product under product manager as soon as they will add price to the product and save.

add_action( 'after_wcfm_products_manage_pricing_fields', function( $product_id ) {
global $WCFM, $WCFMmp;
echo '<p class="description" style="color:#f86c6b; font-size:15px;">Estimated Commission: ';
if( $product_id ) {
$product = wc_get_product( $product_id );
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$commission_rule = $WCFMmp->wcfmmp_product->wcfmmp_get_product_commission_rule( $product_id );
if( $sale_price ) {
$item_commission = $WCFMmp->wcfmmp_commission->wcfmmp_generate_commission_cost( $sale_price, $commission_rule );
} else {
$item_commission = $WCFMmp->wcfmmp_commission->wcfmmp_generate_commission_cost( $regular_price, $commission_rule );
}
echo wc_price( $item_commission );
} else {
echo "Please save the product first!";
}
echo "</p>";
}, 9 );

Yes No

6.Payment #

6.1.Vendor-Customer Direct Pay Option #

This will help to add and show vendor’s payment options directly under customer’s order details page.

Vendor’s may define their direct pay option like “Bank Details” etc… customer will see this at order details page and new order email.

add_action( 'end_wcfm_vendor_settings', function( $vendor_id ) {
global $WCFM, $WCFMmp;
$wcfm_customer_payment_options = get_user_meta( $vendor_id, 'wcfm_customer_payment_options', true );
?>
<!-- collapsible -->
<div class="page_collapsible" id="wcfm_settings_form_min_order_amount_head">
<label class="wcfmfa fa-cart-plus"></label>
<?php _e('Customer Pay Option', 'wc-frontend-manager'); ?><span></span>
</div>
<div class="wcfm-container">
<div id="wcfm_settings_form_vendor_invoice_expander" class="wcfm-content">
<?php
$WCFM->wcfm_fields->wcfm_generate_form_field( array(
"wcfm_customer_payment_options" => array('label' => __('Payment Options', 'wc-frontend-manager'), 'type' => 'textarea', 'class' => 'wcfm-textarea wcfm_ele wcfm_full_ele', 'label_class' => 'wcfm_title wcfm_ele wcfm_full_ele_title', 'value' => $wcfm_customer_payment_options ),
) );
?>
</div>
</div>
<div class="wcfm_clearfix"></div>
<!-- end collapsible -->
<?php
}, 500 );
add_filter( 'wcfm_marketplace_settings_fields_billing', function( $setting_fields, $vendor_id ) {
if( !wcfm_is_vendor() ) {
$wcfm_customer_payment_options = get_user_meta( $vendor_id, 'wcfm_customer_payment_options', true );
$wcfm_customer_payment_options_field = array(
"wcfm_customer_payment_options" => array('label' => __('Customer Payment Options', 'wc-frontend-manager'), 'type' => 'textarea', 'class' => 'wcfm-textarea wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_customer_payment_options ),
);
$setting_fields = array_merge( $wcfm_customer_payment_options_field, $setting_fields );
}
return $setting_fields;
}, 50, 2 );
add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
global $WCFM, $WCFMmp;
if( isset( $wcfm_settings_form['wcfm_customer_payment_options'] ) ) {
$wcfm_customer_payment_options = $wcfm_settings_form['wcfm_customer_payment_options'];
update_user_meta( $vendor_id, 'wcfm_customer_payment_options', $wcfm_customer_payment_options );
}
}, 500, 2 );
function wcfmmp_vendor_order_customer_payment_options( $order ) {
global $WCFM, $WCFMmp;
echo "<br /><br />";
echo "<h2 style='font-size: 18px; color: #17a2b8; line-height: 20px;margin-top: 6px;margin-bottom: 10px;padding: 0px;text-decoration: underline;'>" . __( 'Payment Details:', 'wc-frontend-manager-ultimate' ) . "</h2>";
echo "<table width='100%' style='width:100%;'><tbody>";
$order_items = $order->get_items( apply_filters( 'woocommerce_purchase_order_item_types', 'line_item' ) );
foreach ( $order_items as $item_id => $item ) {
$product_id = $item->get_product_id();
$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
if( !$vendor_id || !wcfm_is_vendor( $vendor_id ) ) continue;
$wcfm_customer_payment_options = get_user_meta( $vendor_id, 'wcfm_customer_payment_options', true );
if( !$wcfm_customer_payment_options ) continue;
?>
<tr>
<td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;font-weight:600;"><?php echo get_the_title( $product_id ); ?></td>
<td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo wpautop($wcfm_customer_payment_options); ?></td>
</tr>
<?php
}
echo "</tbody></table>";
echo "<br /><br /><br /><br />";
}
add_action( 'woocommerce_order_details_after_order_table', 'wcfmmp_vendor_order_customer_payment_options', 50 );
add_action( 'wcfm_store_invoice_vendor_info_after', function( $vendor_id ) {
$wcfm_customer_payment_options = get_user_meta( $vendor_id, 'wcfm_customer_payment_options', true );
if( $wcfm_customer_payment_options ) {
echo '<br /><div class="vendor-shop-phone"><b>Payment Options -</b><br />' . wpautop($wcfm_customer_payment_options) . '</div><br />';
}
});
add_filter( 'wcfm_is_allow_wc_default_email_customer_details', '__return_true' );

 

Yes No

7.Marketplace #

7.1.Archive Sold By #

Well, in WC product archive pages “Sold By” store label visible with products – 

Now, if you do not want to have this then add this to hide this – 

add_filter( 'wcfmmp_is_allow_archive_product_sold_by', '__return_false' );

Now, this sold by label has many parts – 

  • Sold By Label (as per setting)
  • Store Logo
  • Store Name
  • Store Rating
  • Store Badges (available using WCFM Ultimate)

You also allowed to manage all these components –

1. Hide “Sold By” label –

add_filter( 'wcfmmp_is_allow_sold_by_label', '__return_false' );

2. Hide Store Logo –

add_filter( 'wcfmmp_is_allow_sold_by_logo', '__return_false' );

3. Hide Store Review – 

add_filter( 'wcfmmp_is_allow_sold_by_review', '__return_false' );

4. Hide Store Badges – 

add_filter( 'wcfm_is_allow_badges_in_loop', '__return_false' );

Yes No

7.2.Store List Mobile Sidebar #

Well, in mobile view Store List by default sidebar comes under store lists. Now you may tweak this and show sidebar first and then stores. 

add_filter( 'wcfmmp_is_allow_mobile_sidebar_at_bottom', '__return_false' );

Yes No

7.3.Store Page Mobile Sidebar #

Well, in mobile view Store Page by default sidebar comes under store lists. Now you may tweak this and show sidebar first and then stores. 

add_filter( 'wcfmmp_is_allow_mobile_sidebar_at_bottom', '__return_false' );

Yes No

7.4.New Tab at Store Page #

You have to add this code your child theme’s functions.php –

add_action( 'wcfmmp_rewrite_rules_loaded', function( $wcfm_store_url ) {
add_rewrite_rule( $wcfm_store_url.'/([^/]+)/art_works?$', 'index.php?'.$wcfm_store_url.'=$matches[1]&art_works=true', 'top' );
add_rewrite_rule( $wcfm_store_url.'/([^/]+)/art_works/page/?([0-9]{1,})/?$', 'index.php?'.$wcfm_store_url.'=$matches[1]&paged=$matches[2]&art_works=true', 'top' );
}, 50 );
add_filter( 'query_vars', function( $vars ) {
$vars[] = 'art_works';
return $vars;
}, 50 );
add_filter( 'wcfmmp_store_tabs', function( $store_tabs, $store_id ) {
$store_tabs['art_works'] = 'Art Works';
return $store_tabs;
}, 50, 2 );
add_filter( 'wcfmp_store_tabs_url', function( $store_tab_url, $tab ) {
if( $tab == 'art_works' ) {
$store_tab_url .= 'art_works';
}
return $store_tab_url;
}, 50, 2 );
add_filter( 'wcfmp_store_default_query_vars', function( $query_var ) {
global $WCFM, $WCFMmp;
if ( get_query_var( 'art_works' ) ) {
$query_var = 'art_works';
}
return $query_var;
}, 50 );
add_filter( 'wcfmmp_store_default_template', function( $template, $tab ) {
if( $tab == 'art_works' ) {
$template = 'store/wcfmmp-view-store-art-works.php';
}
return $template;
}, 50, 2);

Using this code I have created ‘Art Works’ new tab.

Well, you have to create a template for adding content for this new tab as well.

Check last part of the code –
add_filter( 'wcfmmp_store_default_template', function( $template, $tab ) {
if( $tab == 'art_works' ) {
$template = 'store/wcfmmp-view-store-art-works.php';
}
return $template;
}, 50, 2);

I have created a template with name – wcfmmp-view-store-art-works.php

and this template should be placed at “wp-content/themes/child theme/wcfm/store” folder.

Yes No

8.Vendor Registration #