Diwali

Wishing you joy this Diwali and Halloween! Enjoy up to 20% OFF on all addons!

Claim Offer
00Day 23Hr 37Min 15Sec
Diwali

Variable Products | Set virtual and downloadable by default

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!

Best Multi Vendor Marketplace Plugin for WordPress › Forums › WCFM – Ultimate › Variable Products | Set virtual and downloadable by default

Viewing 3 reply threads
  • Author
    Posts
    • #39871
      Jay
      Guest

      Hi Team,

      For Simple product, I used following code to set product virtual and downloadable by default.

      function wcfm_product_manage_fields_general_custom_virtual( $general_fields, $product_id, $product_type ) {
      if( isset( $general_fields[‘is_virtual’] ) ) {
      $general_fields[‘is_virtual’][‘dfvalue’] = ‘enable’;
      }
      if( isset( $general_fields[‘is_downloadable’] ) ) {
      $general_fields[‘is_downloadable’][‘dfvalue’] = ‘enable’;
      }
      return $general_fields;
      }
      add_filter( ‘wcfm_product_manage_fields_general’, ‘wcfm_product_manage_fields_general_custom_virtual’, 10, 3 );

      However, it doesn’t work on variable product.
      Only workaround I found was following, but it only works when you edit product.
      Is there any way to set variable product virtual and downloadable by default when you first add product/variations?

      function wcfm_product_data_variations_down_virtual( $variations, $variation_id, $variation_id_key ) {
      global $WCFM, $WCFMu;

      if( $variation_id ) {
      $variations[$variation_id_key][‘is_downloadable’] = ‘enable’;
      $variations[$variation_id_key][‘is_virtual’] = ‘enable’;
      }
      return $variations;
      }
      add_filter( ‘wcfm_variation_edit_data’, ‘wcfm_product_data_variations_down_virtual’, 100, 3 );

      Thanks,
      Jay

    • #39895
      WCFM Forum
      Member

      Hi,

      Use this code ->

      add_filter( 'wcfm_product_manage_fields_variations', function( $variation_fileds, $variations, $variation_shipping_option_array, $variation_tax_classes_options ) {
      	$variation_fileds['is_virtual']['dfvalue'] = 'enable';
      	$variation_fileds['is_downloadable']['dfvalue'] = 'enable';
      	return $variation_fileds;
      }, 50, 4 );

      Thank You

    • #39998
      Jay
      Guest

      Thanks for your help.
      It works!

    • #40008
      WCFM Forum
      Member

      Great … you are welcome 🙂

Viewing 3 reply threads
  • The topic ‘Variable Products | Set virtual and downloadable by default’ is closed to new replies.