Advertisement
palsushobhan

wcfm-customer-pay-options

May 31st, 2021
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.56 KB | None | 0 0
  1. add_filter( 'woocommerce_available_payment_gateways', function( $_available_gateways ) {
  2.     if( apply_filters( 'wcfm_is_allow_gateway_restrict_by_vendor_direct_pay_gateways', true ) ) {
  3.         $vendor_id = 0;
  4.         if( function_exists( 'is_checkout' ) && is_checkout() ) {
  5.             foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  6.                 $cart_product_id = $cart_item['product_id'];
  7.                 $cart_product = get_post( $cart_product_id );
  8.                 $cart_product_author = $cart_product->post_author;
  9.                 if( function_exists( 'wcfm_is_vendor' ) && wcfm_is_vendor( $cart_product_author ) ) $vendor_id = $cart_product_author;
  10.                 break;
  11.             }  
  12.             if( $vendor_id ) {
  13.                 $wcfm_preferred_customer_payment   = get_user_meta( $vendor_id, 'wcfm_preferred_customer_payment', true );
  14.                 if( $wcfm_preferred_customer_payment && is_array( $wcfm_preferred_customer_payment ) && !empty( $_available_gateways ) ) {
  15.                     foreach( $_available_gateways as $gateway => $gateway_details ) {
  16.                         if( !isset( $wcfm_preferred_customer_payment[$gateway] ) ) {
  17.                             unset( $_available_gateways[$gateway] );
  18.                         }
  19.                     }
  20.                 }
  21.             }
  22.         }
  23.     }
  24.     return $_available_gateways;
  25. }, 500 );
  26.  
  27. function wcfmmp_vendor_customer_pay_option( $vendor_id ) {
  28.     global $WCFM, $WCFMmp;
  29.     $active_order_payment_methods      = get_wcfm_marketplace_disallow_order_payment_methods();
  30.    
  31.     $wcfm_preferred_customer_payment   = get_user_meta( $vendor_id, 'wcfm_preferred_customer_payment', true );
  32.     $wcfm_customer_payment_options     = get_user_meta( $vendor_id, 'wcfm_customer_payment_options', true );
  33.    
  34.     if( did_action( 'wcfm_vendor_settings_after_shipping' ) ) {
  35.         ?>
  36.         <!-- collapsible -->
  37.         <div class="page_collapsible" id="wcfm_settings_form_min_order_amount_head">
  38.             <label class="wcfmfa fa-cart-plus"></label>
  39.             <?php _e('Customer Pay Option', 'wcfm-vendor-direct-pay'); ?><span></span>
  40.         </div>
  41.         <div class="wcfm-container">
  42.             <div id="wcfm_settings_form_vendor_invoice_expander" class="wcfm-content">
  43.             <?php
  44.     } else {
  45.         ?>
  46.         <div class="wcfm_clearfix"></div>
  47.         <div class="wcfm_vendor_settings_heading"><h2><?php _e('Preferred Payment Method(s)', 'wcfm-vendor-direct-pay'); ?></h2></div>
  48.         <div class="wcfm_clearfix"></div>
  49.         <div class="store_address">
  50.         <?php
  51.     }
  52.     ?>
  53.             <?php
  54.             foreach( $active_order_payment_methods as $method_id => $method_title ) {
  55.                 $payment_details_class = '';
  56.                 //if( in_array( $method_id, apply_filters( 'wcfm_vendor_direct_pay_exclude_gateways', array( 'paypal', 'stripe_split', 'wc-booking-gateway' ) ) ) ) {
  57.                   $payment_details_class = 'wcfm_custom_hide'; 
  58.                 //}
  59.                 $WCFM->wcfm_fields->wcfm_generate_form_field(  array(
  60.                                                                                                                             "wcfm_preferred_customer_payment_".$method_id => array('label' => $method_title, 'name' => 'wcfm_preferred_customer_payment['.$method_id.']', 'type' => 'checkbox', 'class' => 'wcfm-checkbox wcfm_ele', 'label_class' => 'wcfm_title checkbox_title checkbox-title wcfm_ele', 'value' => 'yes', 'dfvalue' => isset( $wcfm_preferred_customer_payment[$method_id] ) ? 'yes' : '' ),
  61.                                                                                                                             "wcfm_customer_payment_options_".$method_id   => array('label' => __('Payment Details', 'wcfm-vendor-direct-pay'), 'name' => 'wcfm_customer_payment_options['.$method_id.']', 'type' => 'textarea', 'class' => 'wcfm-textarea wcfm_ele ' . $payment_details_class, 'label_class' => 'wcfm_title wcfm_ele ' . $payment_details_class, 'value' => isset( $wcfm_customer_payment_options[$method_id] ) ? $wcfm_customer_payment_options[$method_id] : '' ),
  62.                                                                                                                             ) );
  63.             }
  64.         ?>
  65.         </div>
  66.     <?php if( did_action( 'wcfm_vendor_settings_after_shipping' ) ) { ?>
  67.     </div>
  68.   <?php } ?>
  69.     <div class="wcfm_clearfix"></div>
  70.     <!-- end collapsible -->
  71.     <?php
  72. }
  73. add_action( 'wcfm_vendor_settings_after_shipping', 'wcfmmp_vendor_customer_pay_option', 500 );
  74. add_action( 'wcfmmp_admin_wcfm_vendor_commission_payment_settings_after', 'wcfmmp_vendor_customer_pay_option', 500 );
  75.  
  76. add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
  77.     global $WCFM, $WCFMmp;
  78.     if( isset( $wcfm_settings_form['wcfm_preferred_customer_payment'] ) ) {
  79.         $wcfm_preferred_customer_payment = $wcfm_settings_form['wcfm_preferred_customer_payment'];
  80.         update_user_meta( $vendor_id, 'wcfm_preferred_customer_payment',  $wcfm_preferred_customer_payment );
  81.     }
  82.     if( isset( $wcfm_settings_form['wcfm_customer_payment_options'] ) ) {
  83.         $wcfm_customer_payment_options = $wcfm_settings_form['wcfm_customer_payment_options'];
  84.         update_user_meta( $vendor_id, 'wcfm_customer_payment_options',  $wcfm_customer_payment_options );
  85.     }
  86. }, 500, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement