Showing posts with label cms. Show all posts
Showing posts with label cms. 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.........

Tuesday, January 7, 2014

Roman Number Converter Using Javascript

Javascript 

Number to Roman convert:

function toroman (num) {
if (!+num)
return false;
var digits = String(+num).split(""),
key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
"","I","II","III","IV","V","VI","VII","VIII","IX"],
roman = "",

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

Get Latitude Longitude using Area Zip in PHP

<?php

function getLnt($zip){
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=
".urlencode($zip)."&sensor=false";
$result_string = file_get_contents($url);
$result = json_decode($result_string, true);
$result1[]=$result['results'][0];
$result2[]=$result1[0]['geometry'];
$result3[]=$result2[0]['location'];
return $result3[0];
}

$val = getLnt($zip);
echo "Latitude: ".$val['lat']."<br>";
echo "Longitude: ".$val['lng']."<br>";

?>


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;
}
?>

:)