Rating: 3 stars
I have decided to take the time to make this work and have provided my workaround. The dev should take the time to do so as well…Lets face it, this plugin is useless without being able to view it on the frontend. This may not be the best way, but it works for me.
Add this to your functions.php
function my_javascripts() {
echo '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/includes/js/custom.js"></script>';
}
add_action( 'wp_head', 'my_javascripts' );
function wc_variation_description() {
// get the product
global $product;
// Get the post IDs of all the product variations
$variation_ids = $product->children;
// check if we have variations
if ( empty( $variation_ids ) )
return;
// walk the variations
foreach( $variation_ids as $variation_id ) {
$description = wcpvd_get_variation_description( $variation_id );
$model_name = 'model-'.get_post_meta($variation_id, 'attribute_model', true);
echo '<div class="custom_variation" id="' . $model_name . '">';
echo $description;
echo '</div>';
}
} add_action( 'woocommerce_before_single_variation', 'wc_variation_description' );
Then create a new .js file and call it custom.js. Add this to custom.js
jQuery(window).load(function(){
// Hide all custom_variation divs
jQuery( '.custom_variation').css( 'display', 'none' );
// get the specific select element by id #model
jQuery('select#model').change(function() {
var value = "";
// get the option that has been selected
jQuery( "select#model option:selected" ).each(function() {
// get the value data-attribute, prepend it with "model"
value += "model-" + jQuery( this ).val();
// the variable value will now be identical to the id of one of the wrapping custom_variation divs
});
// Hide all custom_variation divs
jQuery( '.custom_variation').css( 'display', 'none' );
// Display only the custom_variation div witht the specific id
jQuery( '.custom_variation#' + value ).css( 'display', 'block' );
});
});
Last but not least we have to upload the custom.js file to the correct directory: wp-content/themes/yourtheme/includes/js
Whatever the label is for your variation attributes you must change in the code. For example, my variation attribute name is Model. If you view the code I have attached above you will see the word model pretty regularly. If your attribute is called size or anything other than model you MUST change every instance of model to whatever the name of your attribute is.
]]>Rating: 1 star
Sounds good in concept, but you really need to provide a working example of the code that calls the function and displays it on the front end. Not going to do the whole trial and error thing. After several attempts to get the entry to display, it simply won’t. Why? The plugin is supposed to create new post meta for the product and nothing is actually being added that I can see. If you try to call the post meta directly, nothing shows. Will have to come up with my own method to do so via custom fields or something.
**EDIT** – The dev doesn’t seem willing to provide support for the plugin. In order to even use this plugin we need a way to display the descriptions on the front end. All the dev provides is a single helper title, but no functional example…as in all of the important code that actually calls and displays the info.
]]>