Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'woocommerce_available_payment_gateways', function( $_available_gateways ) {
- if( apply_filters( 'wcfm_is_allow_gateway_restrict_by_vendor_direct_pay_gateways', true ) ) {
- $vendor_id = 0;
- if( function_exists( 'is_checkout' ) && is_checkout() ) {
- 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( function_exists( 'wcfm_is_vendor' ) && wcfm_is_vendor( $cart_product_author ) ) $vendor_id = $cart_product_author;
- break;
- }
- if( $vendor_id ) {
- $wcfm_preferred_customer_payment = get_user_meta( $vendor_id, 'wcfm_preferred_customer_payment', true );
- if( $wcfm_preferred_customer_payment && is_array( $wcfm_preferred_customer_payment ) && !empty( $_available_gateways ) ) {
- foreach( $_available_gateways as $gateway => $gateway_details ) {
- if( !isset( $wcfm_preferred_customer_payment[$gateway] ) ) {
- unset( $_available_gateways[$gateway] );
- }
- }
- }
- }
- }
- }
- return $_available_gateways;
- }, 500 );
- function wcfmmp_vendor_customer_pay_option( $vendor_id ) {
- global $WCFM, $WCFMmp;
- $active_order_payment_methods = get_wcfm_marketplace_disallow_order_payment_methods();
- $wcfm_preferred_customer_payment = get_user_meta( $vendor_id, 'wcfm_preferred_customer_payment', true );
- $wcfm_customer_payment_options = get_user_meta( $vendor_id, 'wcfm_customer_payment_options', true );
- if( did_action( 'wcfm_vendor_settings_after_shipping' ) ) {
- ?>
- <!-- 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', 'wcfm-vendor-direct-pay'); ?><span></span>
- </div>
- <div class="wcfm-container">
- <div id="wcfm_settings_form_vendor_invoice_expander" class="wcfm-content">
- <?php
- } else {
- ?>
- <div class="wcfm_clearfix"></div>
- <div class="wcfm_vendor_settings_heading"><h2><?php _e('Preferred Payment Method(s)', 'wcfm-vendor-direct-pay'); ?></h2></div>
- <div class="wcfm_clearfix"></div>
- <div class="store_address">
- <?php
- }
- ?>
- <?php
- foreach( $active_order_payment_methods as $method_id => $method_title ) {
- $payment_details_class = '';
- //if( in_array( $method_id, apply_filters( 'wcfm_vendor_direct_pay_exclude_gateways', array( 'paypal', 'stripe_split', 'wc-booking-gateway' ) ) ) ) {
- $payment_details_class = 'wcfm_custom_hide';
- //}
- $WCFM->wcfm_fields->wcfm_generate_form_field( array(
- "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' : '' ),
- "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] : '' ),
- ) );
- }
- ?>
- </div>
- <?php if( did_action( 'wcfm_vendor_settings_after_shipping' ) ) { ?>
- </div>
- <?php } ?>
- <div class="wcfm_clearfix"></div>
- <!-- end collapsible -->
- <?php
- }
- add_action( 'wcfm_vendor_settings_after_shipping', 'wcfmmp_vendor_customer_pay_option', 500 );
- add_action( 'wcfmmp_admin_wcfm_vendor_commission_payment_settings_after', 'wcfmmp_vendor_customer_pay_option', 500 );
- add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
- global $WCFM, $WCFMmp;
- if( isset( $wcfm_settings_form['wcfm_preferred_customer_payment'] ) ) {
- $wcfm_preferred_customer_payment = $wcfm_settings_form['wcfm_preferred_customer_payment'];
- update_user_meta( $vendor_id, 'wcfm_preferred_customer_payment', $wcfm_preferred_customer_payment );
- }
- 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 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement