Forum Replies Created

Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • in reply to: Need Radio fields in Form Helper #58558
    Daniel
    Participant

    Hi Anna,
    But as you know its essential field in forms. Any planning to add this in future versions?

    Thank you

    in reply to: Force Featured Image in Product Edit Form without WP_die #43308
    Daniel
    Participant

    @digitalchild, thanks for that huge distinction and clarification. I suspected, but couldn’t name that concern. Meanwhile, when do you expect the next minor release to happen? If it’s coming soon, we might as well wait for the release…. and glad to have contributed.

    in reply to: Force Required Image #43211
    Daniel
    Participant

    Resubmitted the last post on a new thread:

    Thanks

    in reply to: Force Required Image #42870
    Daniel
    Participant

    Okay, so spending a couple of hours tinkering with how to require a featured image, and have the error come up on the Edit Product page rather than in the WP_Die screen and confues users, the idea came to me that I could create an additional, required wcv custom field that would be hidden with CSS. The value of that field – and its associated meta-key – would get updated automatically depending on whether the product has a featured image attached, in other words if has_post_thumbnail() returns TRUE or FALSE. Since a FALSE result would update the value of the associated field, and the field is required, voila, a data-error message gets thrown.

    I have it working… almost. I’ll mention what I need help with below.

    Here’s the code in the product-edit form:

    
    	<div class="all-100"> 
        	<!-- Media uploader -->
    		<div class="wcv-product-media">
    			<?php WCVendors_Pro_Form_helper::product_media_uploader( $object_id );
    			
    			// Hidden field - Pass the has_thumbnail() value to its metatag value & throw an error on the page if there's no custom field
    			
    			// do_action( 'check_for_featured' , $object_id );
    			
    			// Create the hidden field and the associated meta-key.
    			
    			$has_thumb = get_post_meta( $object_id , 'wcv_custom_product_has_thumbnail', true );
    			$has_thumb == 1 ? $f = '1' : $f = '' ;
    			
    			WCVendors_Pro_Form_Helper::input( array(  
    				 'type'      => 'text',
    				 'post_id'   => $object_id, 
    				 'id'     => 'wcv_custom_product_has_thumbnail',  
    				 'label' => __('Has Featured Image', 'wcvendors-pro'),
    				 'placeholder'   => __( 'Has Featured Image', 'wcvendors-pro' ), 
    				 'wrapper_start' 	=> '<div class="hidden-field">',
    				 'wrapper_end' 		=> '</div>',		
    				 'value' => $f,
    				 'custom_attributes' => array(
    				 	'data-rules' => 'required',
    					'data-error' =>  __( 'Please add a Featured Image.', 'wcvendors-pro') )
    			) );
    			
    			do_action( 'check_for_featured' , $object_id );			
    						
    	?>
       </div>
    
    

    The Media Uploader in the code content above is the one that comes standard with the product-edit.php template, so the code I’ve added is below.

    Here’s what I’ve got in the associated plugin file (it could run via the functions.php file just as well):

    
    // REQUIRE THE FEATURED IMAGE
    function check_product_featured_image( $product_id ) {
    	
    	global $product;
    	global $post;
         
    	$post_type = get_post_type( $product_id );
    	$post_thumb = has_post_thumbnail( $product_id );
    		 
    	if ( $post_thumb && $post_type == 'product' ) {  
    		 	$has_featured = "1"; 
    		}	
    	else { 
    		$has_featured = "0"; 
    		}
    
    	update_post_meta( $product_id , 'wcv_custom_product_has_thumbnail' , $has_featured );
    
    }
    
    add_action( 'check_for_featured' , 'check_product_featured_image' );
    add_action( 'pre_post_update' , 'check_product_featured_image' );
    add_action( 'wcv_save_product_meta', 'check_product_featured_image', 10 );
    

    The field updates successfully, except in the one condition that matters once – when there’s no existing featured image on form load, then the user uploads one. Since the field doesn’t update until the form is saved, the unchanged meta data in my custom field doesn’t change, and still throws the error (I think this may have been the issue with the plugin suggested in this thread as well).

    So… How can I get the metadata and field to update when the image is added or removed? It would be great if there’s a place to hook into, or a function to call, and I figure there must be, because the “Add/Remove” text changes depending on there being an image, updating in real time.

    Thanks for your help!

    in reply to: Force Required Image #42862
    Daniel
    Participant

    @fervous, the code snippet you posted works quite well. If there’s a way to have it throw an error on the form as the other fields do, rather than use ‘wp_die’ that would make for a much better user experience. I think being able to handle that aspect is worth at least a little digging. I may dig around to figure out how to do that for a bit, but any suggestions here would be welcome.

    Also worth noting, the plugin that’s been suggested threw an error regardless of whether I had a featured image or not, and regardless if it was sized appropriately. I know it’s not a WC Vendors plugin, but thought it would be worth mentioning here for other people who might be trying to accomplish similar goals.

    Thanks!

    in reply to: Media Uploader Show Saved Image? #40760
    Daniel
    Participant

    Worked beautifully.

    Thanks!

    in reply to: Woocommerce bookings support #40376
    Daniel
    Participant

    Hello,

    @ben, any updates on that ‘shitload’ of work mentioned above? I’m looking to integrate WC Vendors Pro with Woocommerce Bookings, as the integration would do exactly what we need. I totally understand the inability to predict how and when it will happen as yet. Documentation on how to do the integration ourselves would be great if it exists as well, if version 1.4 isn’t forthcoming for awhile.

    I noticed in this thread https://www.wcvendors.com/help/topic/multi-vendor-plugin-for-woocommerce-services-appointment-plugin/ that Jeffrey may have figured it out at least partway, and the possibility of documentation was mentioned.

    Any update on progress and/or documentation would be of great help.

    Thanks!

    in reply to: Force Required Image #39643
    Daniel
    Participant

    Hello,

    I’m trying to do the force featured image thing too, requiring a featured image for vendor-submitted products before submission is allowed. I tried the plugin mentioned above to no avail. So I’m thinking it will have to happen through code. Ran into the same problems as the people above, as the product media uploader is coded differently than the other product fields. Any further details on how to work with has_post_thumbnail and the_post_thumbnail would be greatly appreciated.

    Thanks!

    Daniel
    Participant

    Ok, that’ll have to do. Thanks.

    Daniel
    Participant

    FYI,

    I figured out a solution that works for our needs. This is a solution that gets a multi-select field to integrate with a custom taxonomy – basically every time the vendor updates the wc-vendor field multi-select field in the front-end product-edit.php form and saves, the taxonomy terms get updated too. When an admin changes the taxonomy terms via the taxonomy’s metabox on the back end product editor, the array value of the WC Vendor custom field is not updated with the code as it is here. For our purposes, that’s fine, since the code does pull the terms from the taxonomy to populate both the front end product page, and the edit-product form next time the vendor goes to edit the product.

    Noting too that this solution isn’t as elegant as Lars’s yet, since it only handles one multi-select custom field + taxonomy at a time, but it’s a good prototype that can be generalized later.

    First, create the taxonomy and the terms using a plugin like Custom Post Types UI, or if you’re the hardcode type, create it yourself.

    And then here’s the code (set up for our Food Types taxonomy, but replace that with whatever you like:

    In Functions.php or a custom plugin…

      
    // Food Type - Array/Taxonomy-Connected Field
    add_action('woocommerce_product_meta_start', 'wcv_food_type', 2);
    function wcv_food_type() {
    	$gid = get_the_ID();
        $food_types = get_post_meta( $gid, 'wcv_custom_product_food_type', true ); // Set the meta key
    	$food_types_terms = (array)get_the_terms( $gid, 'food_type' );
    
    	echo '<h3>Food Types</h3>';
    
    	// Note that this calls the Taxonomy that's associated with the WC Vendors variable
    	foreach ($food_types_terms as $key => $value) {
    		$food_types_term = get_term( $value , 'food_type' );
    		$h = $food_types_term->name;
    		$i = wc_clean($h);
    		echo $i . '<br>';
    	 }
    	echo '<br>';
    }
    
    add_action( 'wcv_save_product_meta', 'food_type_save_product_meta', 10, 1 );
    function food_type_save_product_meta ( $product_id ) {
    	
    	$food_types_names = array();												      // Create an array that will recieve the tax names
    	
    	if ( isset( $_POST[ 'wcv_custom_product_food_type' ] ) ) { 
    
       		$food_types = get_post_meta( $product_id, 'wcv_custom_product_food_type', true ); // Get the wcv array values
    		
    		if ($food_types) {
    		
    			foreach ($food_types as $key => $value) {
    				$food_type_name = get_term( $value , 'food_type' );
    				$f = $food_type_name->name;
    				$g = wc_clean($f);
    				$food_types_names[] = $g;
    			}
    			wp_set_object_terms( $product_id, $food_types_names , 'food_type' );
    			}	}
    		
    	else {
    		delete_post_meta( $product_id, 'wcv_custom_product_food_type' );			// delete the contents of the wcv variable
    		wp_set_object_terms( $product_id, NULL , 'food_type' );  					// and delete the contents of the taxonomy			
    		}			
    	}	
    

    and in product-edit.php…

    
    			// Food Type Custom Field
    			
    			$food_type = (array)get_the_terms( $object_id, 'food_type' );
    			
    			WCVendors_Pro_Form_Helper::select2( apply_filters( 'wcv_custom_product_food_type', array( 
    				'post_id'			=> $object_id, 
    				'id' 				=> 'wcv_custom_product_food_type[]', 
    				'label'   			=> __( 'Food Type (Select all that apply)', 'wcvendors-pro' ), 
    				'placeholder'   	=> __( 'Food Type', 'wcvendors-pro' ), 
    				'wrapper_start' 	=> '<div class="all-100">',
    				'wrapper_end' 		=> '</div>', 
    				'desc_tip'   		=> 'false', 
    				'taxonomy'			=> 'food_type',
    				'taxonomy_args'		=> array( 'hide_empty'=>false ),
    				'value' 			=> $food_type,
    				'custom_attributes' => array( 'multiple' => 'multiple' )
    				
    				) )
    			);	
    

    Note also that for the ability to multi-select, for us it seemed only to work with the ‘select2’ input class, and not at all with the ‘select’ class.

    Hope this is of service.

    Daniel
    Participant

    Thanks Lars! I’m going to be spending a bit of time with this later in the afternoon. I’ll share back here on results and/or issues, as I’m certain that this thread will be useful to others too.

    Daniel
    Participant

    Caught the error in my last post – ‘wcv_custom_food_type’ should be ‘wcv_custom_product_food_type.’ Fixed that; no change in behavior. Thx.

    Daniel
    Participant

    Lars & Ben,

    Thanks for your help…. I think we’ve clarified the problem somewhat, but still not getting what’s needed here. Here’s the current code:

    in Product-edit.php:

    			$food_type_value = get_post_meta( $object_id, 'wcv_custom_product_food_type', true );
    			$food_type_options = array (  
    				'vegan'   => __( 'Vegan', 'wcvendors-pro' ),  
    				'vegetarian'   => __( 'Vegetarian', 'wcvendors-pro' ),  
    				'raw'      => __( 'Raw', 'wcvendors-pro' ),
    				'organic'      => __( 'Organic', 'wcvendors-pro' ),
    				'gluten-free'      => __( 'Gluten Free', 'wcvendors-pro' ),	
    			); 
    			
    			WCVendors_Pro_Form_Helper::select( apply_filters( 'wcv_custom_product_food_type', array( 
    				'post_id'			=> $object_id, 
    				'id' 				=> 'wcv_custom_product_food_type[]', 
    				'label'   			=> __( 'Food Type (Select all that apply)', 'wcvendors-pro' ), 
    				'placeholder'   	=> __( 'Food Type', 'wcvendors-pro' ), 
    				'wrapper_start' 	=> '<div class="all-100">',
    				'wrapper_end' 		=> '</div>', 
    				'desc_tip'   		=> 'false', 
    				'taxonomy'			=> 'food_type',
    				'taxonomy_args'		=> array( 'hide_empty'=>false ),
    				'custom_attributes' => array( 'multiple' => 'multiple' ),
    				'options' 			=> $food_type_options,  
    				'value'             => $food_type_value
    				) )
    			);

    and in Functions.php:

    // Food Type
    add_action('woocommerce_product_meta_start', 'wcv_food_type', 2);
    function wcv_food_type() {
        $food_types = get_post_meta( get_the_ID(), 'wcv_custom_product_food_type', true ); // Set the meta key
    	// If top level array exists
    	foreach ($food_types as $key => $value) : 
    		echo 'food_types' . $key . ' => ' . $value . '<br>';
    	endforeach;
    	echo '<br>';
    }
    
    add_action( 'wcv_save_product_meta', 'food_type_save_product_meta', 10, 1 );
    function food_type_save_product_meta ( $product_id ) {
    
    	// product meta - usage food type
    	if ( isset( $_POST[ 'wcv_custom_food_type' ] ) ) { 
    
    		$food_types = $_POST[ 'wcv_custom_food_type' ];
    		print_r( $food_types);
    
    		if ( ! empty( $food_types ) ) {
    			foreach ( $food_types as $food_type ) { $food_type = wc_clean( $food_type ); }
    			update_post_meta( $product_id, 'wcv_custom_food_type', $food_types ); 
    			update_post_meta( $product_id, 'food_type', $food_types ); 
    		} else {
    			delete_post_meta( $product_id, 'wcv_custom_food_type' );
    			delete_post_meta( $product_id, 'food_type' );    
    		}
    	}    
    }			

    Here’s what’s being reported in the Product Page:

    
    food_types0 => 30
    food_types1 => 29
    

    The code is apparently saving the selected ‘food_type’ taxonomy terms to the ‘wcv_custom_product_food_type’ array variable when the vendor adds the options in the product-edit form, and the numerical array values being echoed on the product page are the ID’s of the taxonomy terms. However, the selected options/tax terms are not actually being added to the product from what I can tell on the back end, or on the product-edit form on reload. The terms are not checked on the ‘food_type’ taxonomy’s metabox in the product/post back end editor after saving. They’re also not appearing in the admin column on the back end woocommerce ‘products’ listing page. So… something is still missing, or maybe 2 things are.

    First, I’m suspecting that the option values echoed on the front-end product page should be taxonomy term names, and not their numerical values. The numerical values seem to be what’s being saved as the ‘value’ part of the ‘key/value’ pair, and I’m not sure why. Maybe that’s the whole problem?

    Second, perhaps the values are not being passed properly from the ‘wcv_custom_product_food_type’ variable to the actual ‘food_type’ taxonomy?

    I’m not sure why, still getting my sea legs with PHP, and probably need some hand holding here.

    Thanks!

    Daniel
    Participant

    Ok, that’s working, but one further question. We still need to differentiate the two data-error handlers – one for not filling in the required field, the other for going over 120 characters.

    Here’s what we currently have, and the error handlers are not working as intended.

    			// Language Spoken Field
    			WCVendors_Pro_Form_Helper::input( array(  
    				 'type'      => 'text',
    				 'post_id'   => $object_id, 
    				 'id'     => 'wcv_custom_product_language_spoken', 
    				 'label'    => __( 'Language Spoken by Staff', 'wcvendors-pro' ), 
    				 'placeholder'   => __( 'Language Spoken by Staff', 'wcvendors-pro' ), 
    				 'desc_tip'    => 'true', 
    				 'description'   => __( 'Language Spoken by Staff', 'wcvendors-pro' ),
    				 'custom_attributes' => array( 
    				 	'multiple' => 'multiple',
    				 	'data-rules' => 'max_length[120]|required',
    					'data-error' => __( 'Maximum 120 Characters|This field is required.', 'wcvendors-pro' ))					  
    			) );

    Thanks!

    Daniel
    Participant

    Ok, the images are failing… trying this link to the public google drive folder.

    https://drive.google.com/open?id=0B9L_6DOCutEEOUN6X3l2c3ZaTmM

    Daniel
    Participant

    Ok, thanks.

    We’re experiencing a host of other issues, somewhat related to this, but not entirely, so going to start a new thread.

    Thanks.

    Daniel
    Participant

    Thanks Jamie, this is working. I do have another couple of questions however:

    1) if I have a field that needs a character limit and is required, how do I do that? Is it possible to make data-rules an array like this:

    			WCVendors_Pro_Form_Helper::input( array(  
    				 'type'      => 'text',
    				 'post_id'   => $object_id, 
    				 'id'     => 'wcv_custom_product_language_spoken', 
    				 'label'    => __( 'Language Spoken by Staff', 'wcvendors-pro' ), 
    				 'placeholder'   => __( 'Language Spoken by Staff', 'wcvendors-pro' ), 
    				 'desc_tip'    => 'true', 
    				 'description'   => __( 'Language Spoken by Staff', 'wcvendors-pro' ),
    				 'custom_attributes' => array( 
    				 	'multiple' => 'multiple',
    				 	'data-rules' => array (
    						'max_length[120]',
    						'required'))				  
    			) );

    I’m testing this now, and it doesn’t seem to be working. It’s not throwing the error for the required field. Let me know how I’d do this, and how I’d specify the errors for both cases.

    In a more general sense, is there documentation anywhere on how to set all the options of the input arrays for these fields? I can’t find any reference on this site beyond the single case example in the “Adding a Custom Field for Products” KnowledgeBase article; I’ve spent a couple hours getting familiar with WP form inputs in general, but it looks like WC Vendors & Pro overlay that functionality and have a language of their own. A reference, if it exists would be great to have access to, and if it doesn’t would be a fabulous thing to create and share.

    Thanks!

    in reply to: WC Vendors Custom Fields & Calling Via FacetWP #37840
    Daniel
    Participant

    Turns out it was a theme conflict. Switching to another theme did the trick. What seems to be the issue is that the Listable theme, with its own built-in facetWP configurationns may actually blocking facets from working that aren’t actually calling variables defined within Listable’s own parameters… including facets that are calling custom WC-vendors fields. This is only a speculation. Rather than investigate deeply, we just went with another theme.

    Daniel
    Participant

    Ok…. mark this one as resolved, simple/stupid answer. We din’t have Screen Options > Custom Fields enabled in the back end product editor. The fields are all there. Hope this helps other people getting lost in the same confusion.

    Thanks.

Viewing 19 posts - 1 through 19 (of 19 total)