Latest Post
Tampilkan postingan dengan label woocommerce. Tampilkan semua postingan
Tampilkan postingan dengan label woocommerce. Tampilkan semua postingan

Add shortcode to template file in woocommerce or wordpress

Written By Unknown on Rabu, 30 Oktober 2013 | 02.20

Shortcode API, a simple set of functions for creating macro codes for use in post content. It enables plugin developers to create special kinds of content (e.g. forms, content generators) that users can attach to certain pages. For instance, the following shortcode (in the post/page content) would add a photo gallery into the page:     [gallery]

But this syntax work for only wp-admin post editor. If you want to add shortcode to your template file then you can use

<?php
        echo do_shortcode( '[shortcode_name]' );
 ?>
It will do same work as done by shortcode when it is added to post...

Add custom price to product in woocommerce

Written By Unknown on Sabtu, 19 Oktober 2013 | 02.25

Woocommerce saves its product price in a dynamic database table in serialized form which are present on cart..... Hence we cannot edit it directly ...

So , to add your custom price use below code:

function add_custom_price( $cart_object) {

  $custom_price = 1151; // This will be your custome price 

  foreach ( $cart_object->cart_contents as $key => $value ) {
            $value['data']->price = $my_sess['price'];
        }
    } 
 add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' )
;

 If you dont know where to add this code ... Add it at the top of wocommerce-functions.php file present in wocommerce plugin
 Yippe .. Now you got your custom price for the products :)

How cart details(product_id,prices,quantity etc) are stored by woocommerce ?

Written By Unknown on Selasa, 15 Oktober 2013 | 22.43

Various information about cart are stored by woocmmerce by two ways:
1. In $woocommerce object( About session , cart info, subtotal etc)
2. In database table named persistent_cart which is dynamic ... it will get destroyed as soon as checkout is done.

So , now how to access all this info ...
For the 1st kind just declare global $woocommerce object and use below code to see all details

global $woocommerce;
echo "<pre>";
print_r($woocommerce);
exit;

For the 2nd kind you have to  fetch data from table.. therefore first declare $wpdb wordpress object and write sql query to get result
one thing to note here is... data is stored in serialize manner in woocommerce_persistent_cart table so you have to unserialize it before using it
only then you can use it. Below is code to get cart information from table

global $wpdb;
$array = $wpdb->get_results("select meta_value from ".$wpdb->prefix."usermeta where meta_key='_woocommerce_persistent_cart'");
//print_r($array);
$data =$array[0]->meta_value;
$de=unserialize($data);

Redirect to a url after login in wordpress/woocommerce


By default you are redirected to my account page in  wordpress/woocommerce after login.
If you want to redirect to some other url use the code below:

add_filter('woocommerce_login_redirect', 'ras_login_redirect');

function ras_login_redirect( $redirect_to ) {
     $redirect_to = "www.google.com";    

     return $redirect_to;
}


If you provide some value to $redirect_to you will be redirected to that url otherwise
you will be redirected to my account as due to default settings in wordpress.

Update value of $wp_session['session_name'] in woocommerce/wordpress

Written By Unknown on Minggu, 13 Oktober 2013 | 23.10

$wp_session = WP_Session::get_instance();
 is method to create your own  session in woocommerce/wordpress.
You can use $wp_session['session_name'] on any file in woocommerce/wordpress
after creating but if you want to change its value you need to first convert this object to array.

For creating array use
$temp = current((array)$wp_session['session_name']);

$temp return you the array / value assigned to $wp_session['session_name']...
Now use or edit $temp as your need and after use assign this array again to $wp_session['session_name']
using

unset ($wp_session['session_name']);
$wp_session['session_name']=$temp;

Example :
$wp_session = WP_Session::get_instance();
$temp = current((array)$wp_session['session_name']);

/***

Work with the array

***/
unset ($wp_session['session_name']);
$wp_session['session_name']=$temp;

Convert $wp_session object to array

$wp_session = WP_Session::get_instance();
 is method to create your own  session in woocommerce/wordpress.
You can use $wp_session['session_name'] on any file in woocommerce/wordpress
after creating but if you want to change its value you need to first convert this object to array.

For creating array use
$temp = current((array)$wp_session['session_name']);

$temp return you the array / value assigned to $wp_session['session_name']...
Now use or edit $temp as your need and after use assign this array again to $wp_session['session_name']
using

unset ($wp_session['session_name']);
$wp_session['session_name']=$temp;

Example :
$wp_session = WP_Session::get_instance();
$temp = current((array)$wp_session['session_name']);

/***

Work with the array

***/
unset ($wp_session['session_name']);
$wp_session['session_name']=$temp;

Use $_SESSION in WordPress/Woocommerce

By default you cannot create your $_SESSION in WordPress/Woocommerce.
The information in $_SESSION remain in only those files on which it is created.
You cant access $_SESSION on  other file.

So, for creating your own session variable you need to install
WP Session Manager plugin.To download you can visit

http://wordpress.org/plugins/wp-session-manager/

And to use the $_SESSION you need to first create session object.
To create object use below line.

$wp_session = WP_Session::get_instance();

and to set value use

$wp_session['session_name']=array('one'=>'1','two'=>'2');
or
$wp_session['session_name']="Your value";


Note: You have to first create session object on every file where you wish to use $wp_session object.
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger