Menu code for drupal 7

/* Menu code for drupal 7 */
<?php
$main_menu_tree = menu_tree(‘main-menu’);
foreach ($main_menu_tree as $key => &$main_menu_item) {
if (is_numeric($key)) {
$main_menu_item[‘#below’][‘#theme_wrappers’][0] = ‘some_other_theme_wrapper’;
}
}
print drupal_render($main_menu_tree);
?>

Backbone.js basics

/* Create Model */
var MessageModel = Backbone.Model.extend();

/* Create Collection with URL */
var MessageCollection = Backbone.Collection.extend({
model: MessageModel,
url: “../api/example_2.php”
});

/* Sent value within URL using collection */
var MessageCollectionNew = Backbone.Collection.extend({
model: MessageModel,
initialize: function(models, options) {
this.url = ‘../api/example_3.php?id=’ + options.id;
},
});

/* Display Message using View */

<!– Templates –>

var MessageView = Backbone.View.extend({
template:_.template($(‘#tpl-hello-backbone’).html()),
render:function (eventName) {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});

/* Router in Backbone.js */
var MessageRouter = Backbone.Router.extend({
/* Display message */
displayMessages: function() {
var messageCollection = new MessageCollection();
var messageListView = new MessageListView({model:messageCollection});
messageCollection.fetch({
success: function () {
$(‘#msg’).html(messageListView.render().el);
}
});
}

/* Send id to collection */
getMsgData: function(id){
var messageCollectionNew = new MessageCollectionNew([], { id: id });
var messageListViewNew = new MessageListViewNew({model:messageCollectionNew});
messageCollectionNew.fetch({
success: function () {
$(‘#data_show’).html(messageListViewNew.render().el);
}
});
},
});

Woo-Commerce change product price in cart

/*Update below code in functions.php it will change cart page and checkout page*/

add_action( ‘woocommerce_before_calculate_totals’, ‘add_custom_price’ );
function add_custom_price( $cart_object ) {
$custom_price = 0.0;

foreach ( $cart_object->cart_contents as $value ) {
if ( $value[‘product_id’] == $free_id ) {

//Woo-Commerce version below 2.7.0
$value[‘data’]->price = $custom_price;

//Woo-Commerce version above 3.0.0
$value[‘data’]->set_price($custom_price);
}
}
}