Created
December 5, 2018 17:22
-
-
Save alpual/652bf1c18630ad127d2254a7dbdc548f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 }}'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This uses Better WooCommerce Stars Shortcode to create the stars.