Saturday, January 28, 2012

Sorting Product Category Widget - WP E-Commerce Plugin Wordpress

Wordpress WP E-Commerce Plugin, There is a widget called Product Category Widget which lists all the product categories. During the site development you may have a lot of categories and nested categories then it will be difficult to sort the list. So here I'm helping you with a bit of code which will sort the products in the widget.

Method 1:

Edit the file :  /wp-content/plugins/wp-e-commerce/wpsc-widgets/category_widget.php
Add the below highlighted code to your php file.

$instance_categories = get_terms( 'wpsc_product_category', 'hide_empty=0&parent=0&orderby=name&order=ASC');
           
 function subval_sort($a,$subkey) {
            foreach($a as $k=>$v) {
                $b[$k] = strtolower($v[$subkey]);
            }
            asort($b);
            foreach($b as $key=>$val) {
                $c[] = $a[$key];
            }
            return $c;
        }
           
            $newArray = array();
            $tempI = $i;
            $i=0;
            foreach($instance_categories as $key=>$value)
           
            {
                $newArray[$i]['term_id'] = $value->term_id;
                $newArray[$i]['name'] = $value->name;
                $newArray[$i]['slug'] = $value->slug;
                $newArray[$i]['term_group'] = $value->term_group;
                $newArray[$i]['term_taxonomy_id'] = $value->term_taxonomy_id;
                $newArray[$i]['taxonomy'] = $value->taxonomy;
                $newArray[$i]['description'] = $value->description;
                $newArray[$i]['parent'] = $value->parent;
                $newArray[$i]['count'] = $value->count;
                $newArray[$i]['sort_order'] = $value->sort_order;
                $i++;
               
            }
            $i = $tempI;
            $newArray = subval_sort($newArray,'name');
           
            $xyz = 0;
            $instance_categories = array();
            foreach($newArray as $key=>$value)
            {
                $instance_categories[$xyz] = (object) $value;   
                $xyz++;
            }
            unset($xyz);
            unset($newArray);


           
            if(!empty($instance_categories)){
                foreach($instance_categories as $categories){


                    $instance['categories'][$categories->term_id] = 'on';
                }
            }

Method 2:  
You can use the below query also to fetch categories and can use it recursively for sub-categories.
 


                                  
    $results =$wpdb->get_results("SELECT name, slug
    FROM wp_term_taxonomy AS wtt
    JOIN wp_terms AS wt ON wt.term_id = wtt.term_id
    WHERE wtt.taxonomy = 'wpsc_product_category'
    AND wtt.parent =$category_id");

    foreach($results as $key=>$value)
    {
    ?>

  • name; ?>

  • }
    ?>                                     

Wednesday, January 25, 2012

PHPMailer with GoDaddy SMTP email script - Resolved.

Here is the working script for PHP Mailer in GoDaddy Hosting,

include("includes/class.phpmailer.php");

date_default_timezone_set('UTC');
define('SMTP_HOST','relay-hosting.secureserver.net');
define('SMTP_PORT',25);
define('SMTP_USERNAME','me@aravindnc.com');
define('SMTP_PASSWORD','me123');
define('SMTP_AUTH',false);

$email = 'aravind_n_c@yahoo.co.in';
$firstName = 'Aravind';

$mail             = new PHPMailerR();
$mail->IsSMTP();
$mail->SMTPDebug                      = 1;                 
$mail->SMTPAuth                           = SMTP_AUTH;                $mail->Host                                   = SMTP_HOST;
$mail->Port                                    = 25;
$mail->Username                           =  SMTP_USERNAME;
$mail->Password                            = SMTP_PASSWORD;
$mail->SetFrom(SMTP_USERNAME,'AravindNC.IN');
$mail->AddReplyTo(SMTP_USERNAME,"AravindNC.IN");
$mail->Subject    = "Welcome to AravindNC.IN";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML('This is a test.');
$mail->AddAddress($email, 'Aravind NC');
$mail->Send();

?>
Share this if you got it working.

Tags : PHPMailer with GoDaddy SMTP email server Script working,

Popular Posts