• mrvince

    (@vincenzbrandl)


    Hey Community,

    I would like to let my Vendors create their own terms and conditions and their own imprint.
    I already found a topic/snippet, that helped me a lot:
    https://wclovers.com/forums/topic/add-custom-fields-on-vendor-store-home/

    BUT:
    This Snippet creates only one Field. When I clone the Snippet, the second Snippets overwrites the first.

    I would like to extend this to TWO separate fields.

    Hope someone can help me with a new Snippet or can show me how to clone the Snippet without overwriting the other.

    Thanks a lot!

    • This topic was modified 4 years ago by mrvince.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Do you want to add additional policy field or want to allow vendors to rename existing policy fields as per their requirement?

    Plugin Author WC Lovers

    (@wclovers)

    Here is snippet to add custom policy field –

    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';
    	}
    	$policy_fields['payment_policy'] = array('label' => __('Payment Policy', 'wc-frontend-manager'), 'type' => $wpeditor, 'class' => 'wcfm-textarea wcfm_ele wcfm_full_ele wcfm_custom_field_editor ' . $rich_editor, 'label_class' => 'wcfm_title wcfm_full_title', 'value' => $_wcfm_vendor_payment_policy );
    	return $policy_fields;
    }, 50, 2 );
    add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
    	if( isset( $wcfm_settings_form['payment_policy'] ) ) {
    		wcfm_update_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', $wcfm_settings_form['payment_policy'] );
    	}	
    }, 20, 2 );
    add_action( 'wcfmmp_store_after_policies', function( $vendor_id ) {
    	$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    	if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) { ?>
    		<div class="policies_area wcfm-payment-policies">
    			<h2 class="wcfm_policies_heading"><?php echo apply_filters('wcfm_payment_policies_heading', __('Payment Policy', 'wc-frontend-manager')); ?></h2>
    			<div class="wcfm_policies_description" ><?php echo $_wcfm_vendor_payment_policy; ?></div>
    		</div>
    	<?php }
    }, 50 );
    add_action( 'wcfm_policy_content_after', function( $product_id ) {
    	global $WCFM;
    	$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
    	if( $vendor_id ) {
    		$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    		if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    			?>
    			<div class="wcfm-payment-policies">
    				<h2 class="wcfm_policies_heading"><?php echo apply_filters('wcfm_payment_policies_heading', __('Payment Policy', 'wc-frontend-manager')); ?></h2>
    				<div class="wcfm_policies_description" ><?php echo $_wcfm_vendor_payment_policy; ?></div>
    			</div>
    			<?php
    		}
    	}
    }, 50 );
    add_action( 'wcfm_order_details_policy_content_after', function( $vendor_id ) {
    	$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    	if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    		?>
    		<tr>
    			<th colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><strong><?php echo apply_filters('wcfm_payment_policies_heading', __('Payment Policy', 'wc-frontend-manager')); ?></strong></th>
    			<td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo $_wcfm_vendor_payment_policy; ?></td>
    	  </tr>
    		<?php
    	}
    }, 50 );
    add_action( 'wcfm_store_invoice_policy_content_after', function( $product_id ) {
    	global $WCFM;
    	$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
    	if( $vendor_id ) {
    		$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    		if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    			?>
    			<tr>
    				<th colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><?php echo apply_filters('wcfm_payment_policies_heading', __('Payment Policy', 'wc-frontend-manager')); ?></th>
    				<td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo $_wcfm_vendor_payment_policy; ?></td>
    			</tr>
    			<?php
    		}
    	}
    }, 50 );
    Thread Starter mrvince

    (@vincenzbrandl)

    Thanks for your response and the snippet!

    I want to add two additional policy fields.

    The snippet only allows me to add one additional field – is there a way to add two additional fields?

    Thank you very much for your effort and best regards!

    Plugin Author WC Lovers

    (@wclovers)

    The snippet only allows me to add one additional field – is there a way to add two additional fields?

    – Just use the same code twice and change field’s name.

    Thread Starter mrvince

    (@vincenzbrandl)

    Unfortunately, that doesn’t work. If I just use the code twice and change the field names, It is automatically showing the entered text of the first box in the second.

    The second duplicated text box is showing on the website, but not in the vendor dashboard. Do you have an idea for this problem? ??

    Plugin Author WC Lovers

    (@wclovers)

    Kindly show me your modified code’s screenshot.

    This field name has to change for the whole code – https://ibb.co/CsNhH8z

    Thread Starter mrvince

    (@vincenzbrandl)

    This is Field 1:

    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';
    	}
    	$policy_fields['payment_policy'] = array('label' => __('Zahlungs- und Versandbedingungen', 'wc-frontend-manager'), 'type' => $wpeditor, 'class' => 'wcfm-textarea wcfm_ele wcfm_full_ele wcfm_custom_field_editor ' . $rich_editor, 'label_class' => 'wcfm_title wcfm_full_title', 'value' => $_wcfm_vendor_payment_policy );
    	return $policy_fields;
    }, 50, 2 );
    add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
    	if( isset( $wcfm_settings_form['payment_policy'] ) ) {
    		wcfm_update_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', $wcfm_settings_form['payment_policy'] );
    	}	
    }, 20, 2 );
    add_action( 'wcfmmp_store_after_policies', function( $vendor_id ) {
    	$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    	if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) { ?>
    		<div class="policies_area wcfm-payment-policies">
    			<h3 class="wcfm_policies_heading"><?php echo apply_filters('wcfm_payment_policies_heading', __('Zahlungs- und Versandbedingungen', 'wc-frontend-manager')); ?></h3>
    			<div class="wcfm_policies_description" ><?php echo $_wcfm_vendor_payment_policy; ?></div>
    		</div>
    	<?php }
    }, 50 );
    add_action( 'wcfm_policy_content_after', function( $product_id ) {
    	global $WCFM;
    	$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
    	if( $vendor_id ) {
    		$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    		if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    			?>
    			<div class="wcfm-payment-policies">
    				<h3 class="wcfm_policies_heading"><?php echo apply_filters('wcfm_payment_policies_heading', __('Zahlungs- und Versandbedingungen', 'wc-frontend-manager')); ?></h3>
    				<div class="wcfm_policies_description" ><?php echo $_wcfm_vendor_payment_policy; ?></div>
    			</div>
    			<?php
    		}
    	}
    }, 50 );
    add_action( 'wcfm_order_details_policy_content_after', function( $vendor_id ) {
    	$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    	if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    		?>
    		<tr>
    			<th colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><strong><?php echo apply_filters('wcfm_payment_policies_heading', __('Zahlungs- und Versandbedingungen', 'wc-frontend-manager')); ?></strong></th>
    			<td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo $_wcfm_vendor_payment_policy; ?></td>
    	  </tr>
    		<?php
    	}
    }, 50 );
    add_action( 'wcfm_store_invoice_policy_content_after', function( $product_id ) {
    	global $WCFM;
    	$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
    	if( $vendor_id ) {
    		$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    		if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    			?>
    			<tr>
    				<th colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><?php echo apply_filters('wcfm_payment_policies_heading', __('Zahlungs- und Versandbedingungen', 'wc-frontend-manager')); ?></th>
    				<td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo $_wcfm_vendor_payment_policy; ?></td>
    			</tr>
    			<?php
    		}
    	}
    }, 50 );

    This is Field 2:

    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';
    	}
    	$policy_fields['payment_policy'] = array('label' => __('Datenschutzerkl?rung', 'wc-frontend-manager'), 'type' => $wpeditor, 'class' => 'wcfm-textarea wcfm_ele wcfm_full_ele wcfm_custom_field_editor ' . $rich_editor, 'label_class' => 'wcfm_title wcfm_full_title', 'value' => $_wcfm_vendor_payment_policy );
    	return $policy_fields;
    }, 50, 2 );
    add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
    	if( isset( $wcfm_settings_form['payment_policy'] ) ) {
    		wcfm_update_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', $wcfm_settings_form['payment_policy'] );
    	}	
    }, 20, 2 );
    
    add_action( 'wcfmmp_store_after_policies', function( $vendor_id ) {
    	$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    	if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) { ?>
    		<div class="policies_area wcfm-payment-policies">
    			<h3 class="wcfm_policies_heading"><?php echo apply_filters('wcfm_payment_policies_heading', __('Datenschutzerkl?rung', 'wc-frontend-manager')); ?></h3>
    			<div class="wcfm_policies_description" ><?php echo $_wcfm_vendor_payment_policy; ?></div>
    		</div>
    	<?php }
    }, 50 );
    
    add_action( 'wcfm_policy_content_after', function( $product_id ) {
    	global $WCFM;
    	$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
    	if( $vendor_id ) {
    		$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    		if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    			?>
    			<div class="wcfm-payment-policies">
    				<h3 class="wcfm_policies_heading"><?php echo apply_filters('wcfm_payment_policies_heading', __('Datenschutzerkl?rung', 'wc-frontend-manager')); ?></h3>
    				<div class="wcfm_policies_description" ><?php echo $_wcfm_vendor_payment_policy; ?></div>
    			</div>
    			<?php
    		}
    	}
    }, 50 );
    
    add_action( 'wcfm_order_details_policy_content_after', function( $vendor_id ) {
    	$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    	if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    		?>
    		<tr>
    			<th colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><strong><?php echo apply_filters('wcfm_payment_policies_heading', __('Datenschutzerkl?rung', 'wc-frontend-manager')); ?></strong></th>
    			<td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo $_wcfm_vendor_payment_policy; ?></td>
    	  </tr>
    		<?php
    	}
    }, 50 );
    
    add_action( 'wcfm_store_invoice_policy_content_after', function( $product_id ) {
    	global $WCFM;
    	$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
    	if( $vendor_id ) {
    		$_wcfm_vendor_payment_policy = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_payment_policy', true );
    		if( !wcfm_empty( $_wcfm_vendor_payment_policy ) ) {
    			?>
    			<tr>
    				<th colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><?php echo apply_filters('wcfm_payment_policies_heading', __('Datenschutzerkl?rung', 'wc-frontend-manager')); ?></th>
    				<td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo $_wcfm_vendor_payment_policy; ?></td>
    			</tr>
    			<?php
    		}
    	}
    }, 50 );

    The Field 2 is not displayed in the Vendor Dashboard, only in the Storefront/Vendorpage and is overtaking the written text from Field 1.

    • This reply was modified 4 years ago by mrvince.
    Plugin Author WC Lovers

    (@wclovers)

    What have you modified?

    I don’t see any changes.

    It’s same as code 1 – https://ibb.co/h9Pn3Ff & https://ibb.co/4713jm2

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add Custom Policy Field for Vendors’ is closed to new replies.