Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
vishalbasnet23 / modify-navigarion-item-wordpress
Last active August 29, 2015 14:07
Modify Navigation item( Changing log in text to My Account after successful login )
function modify_login_menu_item( $item ) {
if(isset($item->title)) {
if( $item->title =='Log in' ) {
if(is_user_logged_in()){
$item->title = 'My Account';
}
} elseif ( $item->title =='My Account' ) {
if(!is_user_logged_in()){
$item->title = 'Login';
@vishalbasnet23
vishalbasnet23 / simple-authentication-function
Created October 10, 2014 06:39
Simple Authentication function
function authentication_redirect () {
if( !is_user_logged_in() ) {
$login_page_url = get_permalink( get_page_by_path( 'log' ) );
wp_safe_redirect($login_page_url);
}
}
@vishalbasnet23
vishalbasnet23 / clear-cart-woocommerce
Created October 10, 2014 06:40
Simple filter to add empty cart url
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
if ( isset( $_GET['empty-cart'] ) ) {
$woocommerce->cart->empty_cart();
}
}
@vishalbasnet23
vishalbasnet23 / override-checkout-fields
Created October 10, 2014 06:44
Override filter for woocommerce checkout fields
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_city']['label'] = 'City';
$fields['billing']['billing_phone']['required'] = false;
$fields['order']['order_comments']['placeholder'] = 'My new placeholder';
//removing fields
unset($fields['order']['order_comments']);
//adding custom fields
$fields['shipping']['shipping_phone'] = array(
'label' => __('Phone', 'woocommerce'),
@vishalbasnet23
vishalbasnet23 / default-country-woocommerce
Created October 10, 2014 06:45
Default Country woocommerce
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
function change_default_checkout_country() {
return 'US'; // country code
}
@vishalbasnet23
vishalbasnet23 / custom-add-to-cart-in-archieve
Created October 10, 2014 06:47
Creating add to cart button for simple products in Archive Page Woocommerce
function custom_add_to_cart_archieve($post_id_as_product) {
global $woocommerce;
$product_factory_custom = new WC_Product_Factory();
$product_object_by_id = $product_factory_custom->get_product($post_id_as_product);
// var_dump($product_object_by_id);
if ( ! $product_object_by_id->is_purchasable() ) return;
?>
<?php
// Availability
@vishalbasnet23
vishalbasnet23 / custom-add-t-cart
Created October 10, 2014 06:48
Custom Add to cart button for woommerce
/**
* Change the add to cart text on product archives
*/
add_filter( 'add_to_cart_text', 'woo_archive_custom_cart_button_text' );
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );
function woo_archive_custom_cart_button_text() {
global $woocommerce;
@vishalbasnet23
vishalbasnet23 / adding-suffix to day of a month jQuery datepicker(st,nd,rd)
Last active August 29, 2015 14:07
Adding suffix to day of a month jQuery datepicker(st,nd,rd)
$( "#dateID" ).datepicker({
dateFormat: 'D M d',
onSelect: function(dateText, inst) {
var dateArr = dateText.split(' ')
var suffix = "";
switch(inst.selectedDay) {
case '1': case '21': case '31': suffix = 'st'; break;
case '2': case '22': suffix = 'nd'; break;
case '3': case '23': suffix = 'rd'; break;
default: suffix = 'th';
@vishalbasnet23
vishalbasnet23 / htmltopdf.js
Last active August 29, 2015 14:07
HTML to PDF Export.
$('table').DataTable( {
dom: 'T<"clear">lfrtip',
tableTools: {
"sSwfPath": "../swf/copy_csv_xls_pdf.swf", //path to your swf folder
"aButtons": [
{
"sExtends": "pdf",
"sPdfOrientation": "landscape",
"sPdfMessage": "Attendence Report For <?php echo get_the_title($event_id_url);?>",
"sButtonText": "Export to PSD"
@vishalbasnet23
vishalbasnet23 / functions.php
Last active August 29, 2015 14:07
html-table-row-export-php
<?php function array2csv(array &$array)
{
if (count($array) == 0) {
return null;
}
ob_start();
$df = fopen("php://output", 'w');
fputcsv($df, array_keys(reset($array)));
foreach ($array as $row) {
fputcsv($df, $row);