How could make "Regular Price" field became "Required" at variable product?

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!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WCFM – Ultimate How could make "Regular Price" field became "Required" at variable product?

Viewing 4 reply threads
  • Author
    Posts
    • #27637
      MOHO
      Participant

      I set price field “Required” at the product custom validation of setting.

      It work at simple product, but not work at variable product.

      How could i solve it?

      By moho

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

      Hi,

      I have give you a code yesterday for variations, please replace that with this code –

      function wcfm_restrict_publish_product_variation_pricing( $variation_fileds, $variations, $variation_shipping_option_array, $variation_tax_classes_options, $products_array ) {
      	global $wp;
      	$product_id = 0;
      	if( isset( $wp->query_vars['wcfm-products-manage'] ) && !empty( $wp->query_vars['wcfm-products-manage'] ) ) {
      		$product_id = absint( $wp->query_vars['wcfm-products-manage'] );
      	}
      	if( $product_id ) {
      		if( get_post_status( $product_id ) == 'publish' ) {
      			if( !current_user_can( 'administrator' ) ) {
      				if( isset( $variation_fileds['regular_price'] ) ) {
      					$variation_fileds['regular_price']['attributes'] = array( 'readonly' => true );
      				}
      				if( isset( $variation_fileds['sale_price'] ) ) {
      					$variation_fileds['sale_price']['attributes'] = array( 'readonly' => true );
      				}
      			}
      		}
      	}
      	if( isset( $variation_fileds['regular_price'] ) ) {
      		$variation_fileds['regular_price']['custom_attributes'] = array( 'required' => 1 );
      	}
      	return $variation_fileds;
      }
      add_filter( 'wcfm_product_manage_fields_variations', 'wcfm_restrict_publish_product_variation_pricing', 50, 5 );

      I have added few more lines in that block, you may only add that part as well –

      if( isset( $variation_fileds['regular_price'] ) ) {
      		$variation_fileds['regular_price']['custom_attributes'] = array( 'required' => 1 );
      	}

      Thank You

    • #27722
      MOHO
      Participant

      Thanks it work now!

      and if i hope the vendor user could edit the price of live product.

      What code should i remove?

    • #27755
      WCFM Forum
      Keymaster

      Hi,

      For simple product I have give you a separate code, just disable that.

      For variation, disable this part –

      if( $product_id ) {
      		if( get_post_status( $product_id ) == 'publish' ) {
      			if( !current_user_can( 'administrator' ) ) {
      				if( isset( $variation_fileds['regular_price'] ) ) {
      					$variation_fileds['regular_price']['attributes'] = array( 'readonly' => true );
      				}
      				if( isset( $variation_fileds['sale_price'] ) ) {
      					$variation_fileds['sale_price']['attributes'] = array( 'readonly' => true );
      				}
      			}
      		}
      	}

      Thank You

    • #27802
      MOHO
      Participant

      thanks a lot!

Viewing 4 reply threads
  • The topic ‘How could make "Regular Price" field became "Required" at variable product?’ is closed to new replies.