Skip to content

Instantly share code, notes, and snippets.

@alpual
Created December 5, 2018 17:22
Show Gist options
  • Save alpual/652bf1c18630ad127d2254a7dbdc548f to your computer and use it in GitHub Desktop.
Save alpual/652bf1c18630ad127d2254a7dbdc548f to your computer and use it in GitHub Desktop.
<?php
//** WooCommerce Stars Shortcodes ***********
//********************************
add_filter( 'vc_gitem_template_attribute_xyn_woo_stars_rating','vc_gitem_template_attribute_xyn_woo_stars_rating', 10, 2 );
function vc_gitem_template_attribute_xyn_woo_stars_rating( $value, $data ) {
extract( array_merge( array(
'post' => null,
'data' => '',
), $data ) );
$atts_extended = array();
parse_str( $data, $atts_extended );
$atts = $atts_extended['atts'];
// write all your widget code in here using queries etc
$title = get_the_title($post->ID);
$link = get_permalink($post->ID);
$terms = get_the_terms($post->ID, 'case_categories');
$output = do_shortcode('[woocommerce_rating]');
return $output;
}
add_filter( 'vc_grid_item_shortcodes', 'xyn_woo_stars_rating_shortcodes' );
function xyn_woo_stars_rating_shortcodes( $shortcodes ) {
$shortcodes['xyn_woo_product_rating'] = array(
'name' => __( 'Woo Stars Rating', 'sage' ),
'base' => 'xyn_woo_product_rating',
'icon' => get_template_directory_uri() . '/assets/images/icon.svg',
'category' => __( 'Content', 'sage' ),
'description' => __( 'Displays the product rating as a number of stars. Requires the Better WooCommerce Stars Shortcode plugin.', 'sage' ),
'post_type' => Vc_Grid_Item_Editor::postType()
);
return $shortcodes;
}
add_shortcode( 'xyn_woo_product_rating', 'xyn_woo_product_rating_render' );
function xyn_woo_product_rating_render($atts){
$atts = vc_map_get_attributes( 'xyn_woo_product_rating', $atts );
return '{{ xyn_woo_stars_rating }}';
}
@alpual
Copy link
Author

alpual commented Dec 5, 2018

This uses Better WooCommerce Stars Shortcode to create the stars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment