Created
October 23, 2014 17:26
-
-
Save bentasm1/545a06018f0ddea1b67a to your computer and use it in GitHub Desktop.
For vdirects customization of WC Vendors
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
// ---- SHOW ALL VENDORS--WITH LIMIT ---- // | |
add_action('woo_vendor_list_shortcode', 'WCV_Vendors'); | |
if (class_exists('WCV_Vendors')) { | |
function pv_vendors( $atts ){ | |
//BASIC CODE FOR SETTING SHORTCODE ATTRIBUTES/PARAMETERS--default at 100 gets overwritten | |
extract( shortcode_atts( array( | |
'limit' => '100', | |
), $atts ) ); | |
//SET VARIABLES | |
// Get the Product Vendor options | |
$pv_settings = get_option('wc_prd_vendor_options'); | |
// Get the Product Vendor shop permalink | |
$pv_perm = $pv_settings['vendor_shop_permalink']; | |
// Only get Vendor users | |
$args = array ('role' => 'vendor', 'orderby' => 'rand'); | |
$vendors = get_users($args); | |
//set html variable | |
$html .= ''; | |
//set iteration variable for loop | |
$i=0; | |
//Loop through all vendors and output a simple link to their vendor pages | |
foreach ($vendors as $vendor) { | |
//if iteration counter is equal to shortcode's limit attribute, stop (break out of) loop | |
if($i==$limit) break; | |
//if vendor shop slug is not empty meaning they completed shop registration and has a link | |
if (!empty($vendor->pv_shop_slug)){ | |
//output | |
$shop_link = site_url($pv_perm.'/' .$vendor->pv_shop_slug ); | |
$html .= '<div style="display:inline-block; margin-right:10%; vertical-align:text-bottom;"><a href="'.$shop_link.'">'.get_avatar($vendor->ID, 100).'</a><br /><a href="'.$shop_link.'">'.$vendor->pv_shop_name.'</a></div>'; | |
//add to iteration counter | |
$i++; | |
}} | |
return $html; | |
} | |
add_shortcode( 'pv_vendors', 'pv_vendors' ); | |
} | |
// ----ADD INDIVIDUAL VENDORS ONE BY ONE---- // | |
add_action('add_woo_vendor_list_shortcode', 'PV_Add_Vendors'); | |
//allows you to add vendor avatar and store link using shortcode. takes attribute of user (username) | |
function pv_add_vendors( $atts ){ | |
//BASIC CODE FOR SETTING SHORTCODE ATTRIBUTES/PARAMETERS | |
extract( shortcode_atts( array( | |
'user' => ' ', | |
), $atts ) ); | |
//SET VARIABLES | |
// Get the Product Vendor options | |
$pv_settings = get_option('wc_prd_vendor_options'); | |
// Get the Product Vendor shop permalink | |
$pv_perm = $pv_settings['vendor_shop_permalink']; | |
// Get user by login | |
$vendor = get_user_by('login', $user); | |
//set html variable | |
$html .= ''; | |
//output | |
$shop_link = site_url($pv_perm.'/' .$vendor->pv_shop_slug ); | |
$html .= '<div style="display:inline-block; margin-right:10%; vertical-align:text-bottom"><a href="'.$shop_link.'">'.get_avatar($vendor->ID, 100).'</a><br /><a href="'.$shop_link.'">'.$vendor->pv_shop_name.'</a></div>'; | |
return $html; | |
} | |
add_shortcode( 'pv_add_vendors', 'pv_add_vendors' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment