Required

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Tagged: 

Viewing 8 reply threads
  • Author
    Posts
    • #18679
      hakanbasaran1978
      Participant

      I want to change some sections as required on the add product page. I show the sections on the attached photos. How i can change them as required?

      Attachments:
      You must be logged in to view attached files.
    • #18682
      WCFM Forum
      Member

      Hi,

      Thanks for get in touch with us.

      Yeah, it’s possible but have to add some custom code for these.

      Let me send that in few hours.

      Thank You

    • #18710
      hakanbasaran1978
      Participant

      Ok Thank You Im Waiting..

      Best Regards,
      Hakan

    • #18721
      WCFM Forum
      Member

      Hi,

      Kindly add this code to your child theme’s functions.php it will make price and stock fields required –

      function wcfm_required_product_fields_pricing( $price_fields, $product_id, $product_type ) {
      	if( isset( $price_fields['regular_price'] ) )  { $price_fields['regular_price']['custom_attributes'] = array( 'required' => 1 ); }
      	return $price_fields;
      }
      add_filter( 'wcfm_product_manage_fields_pricing', 'wcfm_required_product_fields_pricing', 50, 3 );
      function wcfm_required_product_fields_stock( $stock_fields, $product_id, $product_type ) {
      	if( isset( $stock_fields['manage_stock'] ) )  { 
      		$stock_fields['manage_stock']['dfvalue'] = 'enable';
      	  $stock_fields['manage_stock']['custom_attributes'] = array( 'required' => 1 ); 
      	}
      	if( isset( $stock_fields['stock_qty'] ) )  { $stock_fields['stock_qty']['custom_attributes'] = array( 'required' => 1 ); }
      	return $stock_fields;
      }
      add_filter( 'wcfm_product_fields_stock', 'wcfm_required_product_fields_stock', 50, 3 );

      For rests some JavaScript required, I will send those to you soon as well.

      Please know me is this works for you or not!

      Thank You

    • #18722
      WCFM Forum
      Member

      Hi,

      Here is another PHP code snippet to mark “Tags” input required –

      function wcfm_required_product_fields_tags( $tag_fields ) {
      	if( isset( $tag_fields['product_tags'] ) )  { $tag_fields['product_tags']['custom_attributes'] = array( 'required' => 1 ); }
      	return $tag_fields;
      }
      add_filter( 'product_simple_fields_tag', 'wcfm_required_product_fields_tags', 50 );

      Thank You

    • #18727
      hakanbasaran1978
      Participant

      Yess All is Working Thank You ..

      Featured Image
      Description
      Categories

      I am waiting for the codes for 3 sections above. Thank you very much for your help.

      Kings Regards
      Hakan

    • #18753
      WCFM Forum
      Member

      Hi,

      Here is the code for those three fields –

      function wcfm_product_manage_custom_validation( $general_fields, $product_id, $product_type ) {
      	?>
      	<script>
      	// WCFM Form Custom Validation
      	jQuery(document).ready(function($) {
      		$( document.body ).on( 'wcfm_form_validate', function() {
      			// Featured Image
      			$featured_img = $('#featured_img').val();
      			if( !$featured_img ) {
      				if( $wcfm_is_valid_form ) 
      					$('#wcfm-main-contentainer .wcfm-message').html( '<span class="wcicon-status-cancelled"></span>Featured Image: This field is required.' ).addClass('wcfm-error').slideDown();
      				else
      					$('#wcfm-main-contentainer .wcfm-message').append( '<br /><span class="wcicon-status-cancelled"></span>Featured Image: This field is required.' );
      				
      				$wcfm_is_valid_form = false;
      			}
      			
      			// Product category
      			$product_cats = $('#product_cats').val();
      			if( !$product_cats ) {
      				if( $wcfm_is_valid_form ) 
      					$('#wcfm-main-contentainer .wcfm-message').html( '<span class="wcicon-status-cancelled"></span>Categories: This field is required.' ).addClass('wcfm-error').slideDown();
      				else
      					$('#wcfm-main-contentainer .wcfm-message').append( '<br /><span class="wcicon-status-cancelled"></span>Categories: This field is required.' );
      				
      				$wcfm_is_valid_form = false;
      			}
      			
      			// Description
      			$description = '';
      			if( $('#description').hasClass('rich_editor') ) {
      				if( tinymce.get('description') != null ) {
      					$description = tinymce.get('description').getContent({format: 'raw'});
      					$description = $($description).text();
      				}
      			} else {
      				$description = $.trim($('#description').val());
      			}
      			if( !$description ) {
      				if( $wcfm_is_valid_form ) 
      					$('#wcfm-main-contentainer .wcfm-message').html( '<span class="wcicon-status-cancelled"></span>Description: This field is required.' ).addClass('wcfm-error').slideDown();
      				else
      					$('#wcfm-main-contentainer .wcfm-message').append( '<br /><span class="wcicon-status-cancelled"></span>Description: This field is required.' );
      				
      				$wcfm_is_valid_form = false;
      			}
      		});
      	});
      	</script>
      	<?php
      	return $general_fields;
      }
      add_filter( 'wcfm_product_manage_fields_general', 'wcfm_product_manage_custom_validation', 50, 3 );

      Please know me is this works for or not!

      Thank You

    • #18793
      hakanbasaran1978
      Participant

      Thank You ,

      All is Working

      Best Rgrsds,
      Hakan

    • #18816
      WCFM Forum
      Member

      Hi,

      Thanks for confirming me this.

      If you ever get a chance then please give me a review – https://wordpress.org/support/plugin/wc-frontend-manager/reviews/

      Thank You

Viewing 8 reply threads
  • The topic ‘Required’ is closed to new replies.