Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wcfm_get_additional_policies() {
- return array(
- 'privacy' => 'Privacy Policy',
- 'impressum' => 'Impressum Policy',
- 'agb' => 'AGB Policy'
- );
- }
- add_filter( 'wcfm_vendor_settings_fields_policies', function( $policy_fields, $vendor_id ) {
- $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';
- }
- $new_policies = wcfm_get_additional_policies();
- if(!empty($new_policies)) {
- foreach($new_policies as $name => $label) {
- $policy_key = "wcfm_vendor_{$name}_policy";
- $_wcfm_policy = wcfm_get_user_meta( $vendor_id, $policy_key, true );
- $policy_fields["{$name}_policy"] = array('label' => $label, '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_policy );
- }
- }
- return $policy_fields;
- }, 50, 2 );
- add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
- $new_policies = wcfm_get_additional_policies();
- if(!empty($new_policies)) {
- foreach($new_policies as $name => $label) {
- $policy_key = "wcfm_vendor_{$name}_policy";
- if( isset( $wcfm_settings_form["{$name}_policy"] ) ) {
- wcfm_update_user_meta( $vendor_id, $policy_key, $wcfm_settings_form["{$name}_policy"] );
- }
- }
- }
- }, 20, 2 );
- add_action( 'wcfmmp_store_after_policies', function( $vendor_id ) {
- $new_policies = wcfm_get_additional_policies();
- if(!empty($new_policies)) {
- foreach($new_policies as $name => $label) {
- $policy_key = "wcfm_vendor_{$name}_policy";
- $_wcfm_policy = wcfm_get_user_meta( $vendor_id, $policy_key, true );
- if( !wcfm_empty( $_wcfm_policy ) ) { ?>
- <div class="policies_area wcfm-<?php echo $name; ?>-policies">
- <h2 class="wcfm_policies_heading"><?php echo apply_filters("wcfm_{$name}_policies_heading", $label); ?></h2>
- <div class="wcfm_policies_description" ><?php echo $_wcfm_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 ) {
- $new_policies = wcfm_get_additional_policies();
- if(!empty($new_policies)) {
- foreach($new_policies as $name => $label) {
- $policy_key = "wcfm_vendor_{$name}_policy";
- $_wcfm_policy = wcfm_get_user_meta( $vendor_id, $policy_key, true );
- if( !wcfm_empty( $_wcfm_policy ) ) { ?>
- <div class="wcfm-<?php echo $name; ?>-policies">
- <h2 class="wcfm_policies_heading"><?php echo apply_filters("wcfm_{$name}_policies_heading", $label); ?></h2>
- <div class="wcfm_policies_description" ><?php echo $_wcfm_policy; ?></div>
- </div>
- <?php }
- }
- }
- }
- }, 50 );
- add_action( 'wcfm_order_details_policy_content_after', function( $vendor_id ) {
- $new_policies = wcfm_get_additional_policies();
- if(!empty($new_policies)) {
- foreach($new_policies as $name => $label) {
- $policy_key = "wcfm_vendor_{$name}_policy";
- $_wcfm_policy = wcfm_get_user_meta( $vendor_id, $policy_key, true );
- if( !wcfm_empty( $_wcfm_policy ) ) { ?>
- <tr>
- <th colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><strong><?php echo apply_filters("wcfm_{$name}_policies_heading", $label); ?></strong></th>
- <td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo $_wcfm_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 ) {
- $new_policies = wcfm_get_additional_policies();
- if(!empty($new_policies)) {
- foreach($new_policies as $name => $label) {
- $policy_key = "wcfm_vendor_{$name}_policy";
- $_wcfm_policy = wcfm_get_user_meta( $vendor_id, $policy_key, true );
- if( !wcfm_empty( $_wcfm_policy ) ) { ?>
- <tr>
- <th colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><?php echo apply_filters("wcfm_{$name}_policies_heading", $label); ?></th>
- <td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo $_wcfm_policy; ?></td>
- </tr>
- <?php }
- }
- }
- }
- }, 50 );
- add_action('wcfmmp_admin_wcfm_vendor_store_policy_settings_after', function($vendor_id) {
- ?>
- <script>
- jQuery(function($) {
- $(document.body).on('wcfm_form_validate', function(event, form) {
- $form = $(form);
- if($form && $form.attr('id') == 'wcfm_vendor_manage_store_policy_support_setting_form') {
- var privacy_policy = getWCFMEditorContent( 'privacy_policy' );
- var impressum_policy = getWCFMEditorContent( 'impressum_policy' );
- var agb_policy = getWCFMEditorContent( 'agb_policy' );
- $form.find('#privacy_policy').val(privacy_policy);
- $form.find('#impressum_policy').val(impressum_policy);
- $form.find('#agb_policy').val(agb_policy);
- }
- });
- });
- </script>
- <?php
- });
Add Comment
Please, Sign In to add comment