Showing posts with label wordpress. Show all posts
Showing posts with label wordpress. Show all posts

Monday, September 29, 2014

Woocommerce issue when products and categories has same base path

404 on Product detail page?

Ran into this issue where I needed a url structure such as/shop/<category> and /shop/<category>/<product>/.

/shop/<category>/ works fine but once you click a product you get a nice looking 404 page.

My settings:
Product category base - /shop
Product permalink base -> Custom Structure - /shop/%product_cat%

The Fix:

Set the ‘Product category base’ to shop and the custom product base to /shop/%product_cat%.
Then in your functions.php file add this little snippet:

Tuesday, May 27, 2014

Change User role after payment successful on WooCommerce

Add below action and function on function.php file of the current theme.

add_action('woocommerce_thankyou', 'change_user_role_on_order_success');

function change_user_role_on_order_success($order_id ) {
$order = new WC_Order( $order_id );
$user_id = $order->user_id;
$wp_user_object = new WP_User($user_id);
if($wp_user_object->roles[0] != "administrator"){ // Do not change admin role
wp_update_user( array( 'ID' => $wp_user_object->ID, 'role' => "student" ) );
}
}

Change current user role to administrator.

Add below code to function.php file to change all user role to administrator.

//Change User role to any specific.
 $current_user = wp_get_current_user();
 $wp_user_object = new WP_User($current_user->ID);
 $wp_user_object->set_role('administrator');


Cheers.........

Monday, February 24, 2014

Notify a User when his/her Role has Been Changed to Specific Role

Write below code in function.php file.

function user_role_update( $user_id, $new_role ) {
if ($new_role == 'editor') { 
 $site_url = get_bloginfo('wpurl'); 
 $user_info = get_userdata( $user_id ); 
 $to = $user_info->user_email; 
 $subject = "Congrats your Role changed to ".$new_role."";
 $message = "Hello " .$user_info->display_name . ", your role has changed on ".$site_url.", congratulations you are now an " . $new_role; 
 wp_mail($to, $subject, $message); 
 }
}

add_action( 'set_user_role', 'user_role_update', 10, 2);

Tuesday, November 26, 2013

Add Class to Next and Previous links in Wordpress

Write below code in function.php file to add class on next prev links for pagination

<?php 
add_filter('next_posts_link_attributes', 'posts_next_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_prev_link_attributes');

function posts_next_link_attributes() {
return 'class="nav_next_class"';
}

function posts_prev_link_attributes() {
return 'class="nav_prev_class"';
}
?>

above function will add "nav_next_class" to next link and "nav_prev_class" to previous link.
:)


Saturday, November 9, 2013

Change FromName and FromEmail For Wordpress

Open your theme function.php file to setup new fromname and fromemail for Site emails.

<?php
add_filter('wp_mail_from','mail_from');
add_filter('wp_mail_from_name','mail_from_name');

function mail_from()
{

global $mail_from_opt;

if (empty($mail_from_opt['username'])) : $username = "Bhumika"; endif;
$domainname = strtolower( $_SERVER['SERVER_NAME'] );
if ( substr( $domainname, 0, 4 ) == 'www.' ) {
$domainname = substr( $domainname, 4 );
}
$emailaddress = $username.'@'.$domainname;

return $emailaddress;
}

function mail_from_name()
{

global $mail_from_opt;

if (empty($mail_from_opt['sendername'])) : $sendername = "Bhumika"; endif;

return $sendername;
}
?>

:)