Skip to content

Instantly share code, notes, and snippets.

View FernandoSalinas33's full-sized avatar

Fernando Salinas FernandoSalinas33

View GitHub Profile
@FernandoSalinas33
FernandoSalinas33 / functions.php
Created July 31, 2018 17:25
Hide certain menu items based on role
function add_custom_menus(){
$user = wp_get_current_user();
if ( in_array( 'employer', (array) $user->roles ) ) {
//The user has the "author" role
echo '<style type="text/css">.woocommerce-MyAccount-navigation-link--downloads {display: none;}.woocommerce-Addresses .u-column2 {display: none;}</style>';
}elseif ( in_array( 'candidate', (array) $user->roles ) ) {
//The user has the "author" role
echo '<style type="text/css">.woocommerce-MyAccount-navigation-link--downloads {display: none;}.woocommerce-MyAccount-navigation-link--orders {display: none;}.woocommerce-MyAccount-navigation-link--edit-address {display: none;}</style>';
}
}
@FernandoSalinas33
FernandoSalinas33 / functions.php
Created July 30, 2018 21:36
Add # of reviews a listing has on the listing card
add_filter( 'listify_get_listing_to_array', function( $data, $listing ) {
$count = get_comments_number( $listing->get_id() );
// Only add if our custom field is not empty.
if ( '' !== $count ) {
if($count == 1){$data['countz'] = $count ." Review";}
else{ $data['countz'] = $count ." Reviews";}
}
@FernandoSalinas33
FernandoSalinas33 / functions.php
Created July 23, 2018 18:48
Make Vendor Admin the default WooCommerce Registration Role
add_filter('woocommerce_new_customer_data', 'wc_assign_custom_role', 10, 1);
function wc_assign_custom_role($args) {
$args['role'] = 'wc_product_vendors_admin_vendor';
return $args;
}
@FernandoSalinas33
FernandoSalinas33 / gist:8416fe6d4ac882d37501efd4fb9f53f9
Created July 3, 2018 19:31
Edit the order of the Categories filter
//See available parameters: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
add_filter( 'listify_wp_job_manager_filters_dropdown_category', function( $args ) {
$args['orderby'] = 'id';
return $args;
} );
/**
* Plugin Name: Product Vendors, auto approve
*/
function automaticallyApproveRegisteredVendors ( $vendorData ) {
$vendorData['role'] = 'wc_product_vendors_admin_vendor';
return $vendorData;
}
add_filter( 'wcpv_registration_default_user_data',
'automaticallyApproveRegisteredVendors', 10, 1);
@FernandoSalinas33
FernandoSalinas33 / functions.php
Created June 4, 2018 15:04
Add the rating count on Listing Card
function rating_count_listify_single_job_listing_meta() {
global $post;
$count = listify_get_listing( $post )->get_rating_count();
$text = esc_html( sprintf( _n( '%d Review', '%d Reviews', $count, 'listify' ), $count ) );
// Link.
$link = listify_submit_review_url( $post );
if ( $link && is_singular() ) {
$text = '<a href="' . esc_url( $link ) . '">' . $text . '</a>';
}
// Output.
@FernandoSalinas33
FernandoSalinas33 / functions.php
Created May 4, 2018 14:22
Bypass Logout Confirmation
function wc_bypass_logout_confirmation() {
global $wp;
if ( isset( $wp->query_vars['customer-logout'] ) ) {
wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
exit;
}
}
add_action( 'template_redirect', 'wc_bypass_logout_confirmation' );
@FernandoSalinas33
FernandoSalinas33 / functions.php
Created May 3, 2018 20:15
Add a Button that calls the Listing owner
function custom_listify_single_job_listing_actions_after() {
global $post;
$phone = get_post_meta( $post->ID, '_phone', true );
echo '<a href="tel:' . $phone . '" class="button">My Button</a>';
}
add_filter( 'listify_single_job_listing_actions_after', 'custom_listify_single_job_listing_actions_after' );
@FernandoSalinas33
FernandoSalinas33 / functions.php
Created May 2, 2018 13:46
Change WooCommerce Registration Role to Employer.
add_filter('woocommerce_new_customer_data', 'wc_assign_custom_role', 10, 1);
function wc_assign_custom_role($args) {
$args['role'] = 'employer';
return $args;
}
@FernandoSalinas33
FernandoSalinas33 / functions.php
Created April 25, 2018 16:44
increase the number of listings on the stats dashboard from 10 to 20.
add_filter( 'wpjms_job_listing_loop_args', function( $args ) {
$args= array(
'post_type' => array( 'job_listing' ),
'author' => get_current_user_id(),
'posts_per_page' => 20,
);