Skip to content

Instantly share code, notes, and snippets.

View sushobhan-pal's full-sized avatar

sushobhan-pal

View GitHub Profile
@sushobhan-pal
sushobhan-pal / commission-calculatetion-special-case.php
Created June 11, 2021 07:34
#Transaction charge fully bear by vendors. Admin will not contribute. Calculate #Commission tax only on admin commission value.
//Transaction charge fully bear by vendors. Admin will not contribute
add_filter( 'wcfmmp_commission_deducted_transaction_charge', function($transaction_charge, $vendor_id, $product_id, $order_id, $total_commission, $commission_rule ) {
global $WCFMmp;
$transacton_charge_meta_key = '_wcfmmp_vendor_transacton_charge_'.$vendor_id.'_'.$product_id;
if($transaction_charge = get_post_meta( $order_id, $transacton_charge_meta_key, true )) {
return $transaction_charge;
}
$order = wc_get_order( $order_id );
$vendors = array();
@sushobhan-pal
sushobhan-pal / free-coupon-support-for-wcfm-shipping-methods
Created June 8, 2021 11:47
#FreeCoupon support for Country-based, Weight-based, and Distance rate shipping
add_filter('wcfmmp_free_shipping_minimum_order_amount', function($min_amount, $vendor_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'] : '';
if ( ! $wcfmmp_shipping || empty( $shipping_type ) || $shipping_type == 'by_zone' )
return $min_amount;
if( apply_filters( 'wcfmmp_is_allow_free_shipping_coupon', true ) ) {
$has_free_coupon = false;
$coupons = WC()->cart->get_coupons();
if ( $coupons ) {
@sushobhan-pal
sushobhan-pal / wcfm-custom-store-policy.php
Created January 13, 2021 06:42
Add a custom store policy (payment) for your vendors
<?php
add_filter( 'wcfm_vendor_settings_fields_policies', function( $policy_fields, $vendor_id ) {
$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
$rich_editor = apply_filters( 'wcfm_is_allow_rich_editor', 'rich_editor' );
$wpeditor = apply_filters( 'wcfm_is_allow_product_wpeditor', 'wpeditor' );
if( $wpeditor && $rich_editor ) {
$rich_editor = 'wcfm_wpeditor';
} else {
$wpeditor = 'textarea';
}
@sushobhan-pal
sushobhan-pal / vendor-own-customer-behavior-restriction.php
Created January 8, 2021 14:19
For customer's added from vendor dashboard, restrict accessing other stores or purchase product from other vendors
<?php
add_action( 'template_redirect', function() {
if ( wcfm_is_store_page() ) {
$wcfm_store_url = get_option( 'wcfm_store_url', 'store' );
$store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
$store_id = 0;
if(!empty($store_name)) {
$store_user = get_user_by( 'slug', $store_name );
$store_id = $store_user->ID;
}
@sushobhan-pal
sushobhan-pal / wcfm-vendor-website-url-on-store-page.php
Last active November 27, 2020 14:34
Add a website url field on vendor's settings page and then display that on their store page (with shortcode support)
<?php
add_filter( 'wcfm_marketplace_settings_fields_general', function( $setting_fields, $vendor_id ) {
if( isset($setting_fields['store_name']) ) {
$website_url = get_user_meta( $vendor_id, '_wcfm_vendor_website_url', true );
$vendor_website_url = array(
"_wcfm_vendor_website_url" => array( 'label' => __( 'Website URL', 'wc-frontend-manager' ), 'type' => 'text', 'class' => 'wcfm-text wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => esc_url($website_url) ),
);
$setting_fields = array_merge( $setting_fields, $vendor_website_url );
}
return $setting_fields;
@sushobhan-pal
sushobhan-pal / wcfmgs-clone-a-group.php
Created November 4, 2020 10:36
This will allow cloning of a group from admin dashboard > Groups page
add_action('wcfm_vendor_groups_actions', function($actions, $wcfm_groups_single) {
$actions .= '<a class="wcfm_group_duplicate wcfm-action-icon" href="#" data-groupid="' . $wcfm_groups_single->ID . '"><span class="wcfmfa fa-copy text_tip" data-tip="' . esc_attr__( 'Duplicate', 'wc-frontend-manager' ) . '"></span></a>';
return $actions;
}, 10, 2);
add_action('after_wcfm_groups', function() {
?>
<script>
jQuery(function($) {
$('#wcfm-groups').on('click', '.wcfm_group_duplicate', function(){
@sushobhan-pal
sushobhan-pal / wcfm-cart-item-sort-by-vendor.php
Created October 7, 2020 07:58
Sort cart items alphabetically and also grouped by store name
<?php
add_action( 'woocommerce_cart_loaded_from_session', function() {
$products_in_cart = array();
foreach ( WC()->cart->cart_contents as $key => $item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $item['data'], $item, $key );
$vendor_id = wcfm_get_vendor_id_by_post( $_product->get_id() );
$products_in_cart[ $key ] = wcfm_get_vendor_store_name( $vendor_id )."-".$item['data']->get_title();
}
natcasesort( $products_in_cart );
$cart_contents = array();
@sushobhan-pal
sushobhan-pal / wcfm-stripe-express-account-dashboard-link.php.php
Created September 28, 2020 09:50
Stripe Express Account Vendor Dashboard Link
@sushobhan-pal
sushobhan-pal / wcfm-store-list-page-replace-inquiry-with-follower-button.php
Created September 11, 2020 16:27
This script will hide inquiry button on store list page and instead show Store Follow button
<?php
add_action( 'wcfmmp_store_list_after_store_info', function($store_id) {
global $WCFM;
remove_action( 'wcfmmp_store_list_after_store_info', array( $WCFM->wcfm_enquiry, 'wcfmmp_store_list_enquiry_button' ), 35 );
}, 34 );
add_action( 'wcfmmp_store_list_footer', function($store_id) {
echo do_shortcode( '[wcfm_mod_follow label="" store="' . $store_id . '" background="#17a2b8" color="white"]' );
} );
add_action( 'wcfmmp_store_lists_end', function() {
static $called = false;
@sushobhan-pal
sushobhan-pal / wcfm-product-selling-restrictions.php
Created September 10, 2020 13:44
This script will disable add to cart option from the vendor's product who didn't complete their payment(stripe) or shipping configurations
<?php
add_filter( 'woocommerce_is_purchasable', function($is_purchasable, $product) {
if ( method_exists( $product, 'get_id' ) ) {
$product_id = $product->get_id();
if ( $product_id ) {
$vendor_id = wcfm_get_vendor_id_by_post($product_id);
if($vendor_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'] ) : '' ;
$stripe_user_id = get_user_meta( $vendor_id, 'stripe_user_id', true );