• First, thank you for this awesome plugin! You’ve obviously spent a lot of time on it. I especially appreciate your terrific documentation here and within the code!

    We’re using woocommerce to manage a product catalog, and, because of the way the client wants the users to be able to search and filter products, we’ve implemented custom fields for them…. and we’re using custom fields for the product “variations” as well. Don’t worry if you’re not super familiar with how all this works, that’s just some background to set up what I need to do.

    The custom fields show up perfectly for our product content type. And they and also for our product_variation content type.

    The snag is that you don’t really add product_variations singly. They are added from within a product. So there’s a metabox for product variations when you’re on the product create/edit screen. In that metabox, woo adds its “attributes” and any custom attributes you’ve added… but it doesn’t include any custom fields (attributes are not custom fields; they’re all stored in one field in a serialized array). So… I need to add the custom fields from CCTM to this variations metabox. There is a hook in woo for me to write a function that runs after a variations’ attributes are printed, so I know from that standpoint I can add the custom fields. But… to cut a long story, well, long… what I need to know is:

    What CCTM function do I hook into to print out the custom fields metabox within this metabox, you know, just like it prints out in its own metabox? I’m looking at CCTM_form_element.php and the get_create_field_instance and get_edit_field_instance functions… and I think there is probably something a little higher up in the chain that I should use… something that would call these functions…

    thank you so much!
    tree

    http://wordpress.org/extend/plugins/custom-content-type-manager/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter beingtree

    (@beingtree)

    OK. sorry. I just found print_custom_fields in StandardizedCustomFields.php… I think that may help me get where I need to be. I’ll keep you posted!

    Thread Starter beingtree

    (@beingtree)

    Another update:

    I put this in my theme’s functions.php:

    if (function_exists('StandardizedCustomFields::print_custom_fields')) {
    	add_meta_box( 'cctm_variation_'.$variation_data['variation_post_id']
    		, __('Custom Fields', CCTM_TXTDOMAIN )
    		, 'StandardizedCustomFields::print_custom_fields'
    		, 'product_variation'
    		, 'normal'
    		, 'high'
    		, 'product_variation'
    	);
    	} else {
    		echo "CCTM is not avaiable. Please Make sure it is installed and activated.";
    	}

    The response is “CCTM is not avaiable. Please Make sure it is installed and activated.”

    So is there some other way I need to reference that function? Sorry if it’s elementary and I’m just not getting it for some reason.

    thanks again,
    tree

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    You might be able to pull it off if you first require_once the CCTM.php file and the StandardizedCustomFields.php file… perhaps you need to do 2 checks: 1 for “class_exists” and another for “method_exists”?

    But I have to caution you that this function is intended to be used only during specific cases due to some wonky WP architecture, so your results here may vary… I think that’s a tough row to hoe: the individual form element classes are all designed to save data into one specific part of the WP database (into wp_postmeta as JSON encoded data), and “rerouting” them to save into a 3rd party plugin’s custom location+format is a tall order. You can override some of the behavior by implementing your own version of the classes inside your custom directory inside of wp-content/uploads/cctm/fields/ (classes in that directory would override the classes in the built-in directory inside of the plugins/custom-content-type-manager/fields/ directory), but that’s a lot of overriding, and I wouldn’t hold my breath that it would work seamlessly…. really the crux of this is that it’s the StandardizedCustomFields::save_custom_fields() function that is ultimately controlling where that data gets stored, and THAT function cannot be overridden.

    If I were you, I’d be looking fairly seriously at using a different CMS or framework for something like that… at some point customizing the available plugins takes more work than building it the way you need it in a system that allows for such types of customizations.

    Thread Starter beingtree

    (@beingtree)

    Okeydoke. I got most of it to work, except the Javascript updating… Here’s a gist: https://gist.github.com/beingtree/5535333

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Wow. That’s a lot of work. I’m thinking more and more that the recommendation to do this in a different CMS was the correct one.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘adding custom fields to another plugin's (woocommerce) meta box’ is closed to new replies.