add_filter( 'manage_edit-{custom_post_type}_columns', 'edit_custom_columns' ) ; function edit_custom_columns( $columns ) { $columns = array( 'cb' => '<input type="checkbox" />', 'title' => __( 'Tite' ), 'category' => __( 'Category' ), 'date' => __( 'Date' ) ); return $columns; }
Rename Woo-commerce Order Status Programmatically
function aviweb_renaming_order_status( $order_statuses ) { foreach ( $order_statuses as $key => $status ) { if ( 'wc-processing' === $key ) { $order_statuses['wc-processing'] = _x( 'In progress', 'Order status', 'woocommerce' ); } if ( 'wc-completed' === $key ) { $order_statuses['wc-completed'] = _x( 'Delivered', 'Order status', 'woocommerce' ); } } return $order_statuses; } add_filter( 'wc_order_statuses', 'aviweb_renaming_order_status' );
Redirect website with WWW and without WWW using .htaccess
Redirect without WWW RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.aviweb\.com [NC] RewriteRule ^(.*)$ http://aviweb.com/$1 [L,R=301] Redirect with WWW RewriteEngine on RewriteCond %{HTTP_HOST} ^aviweb\.com [NC] RewriteRule ^(.*)$ http://www.aviweb.com/$1 [L,R=301]
Custom post type redirect in WordPress
add_action( 'template_redirect', 'aviweb_redirect_post_type' ); function aviweb_redirect_post_type() { $queried_post_type = get_query_var('post_type'); if ( is_single() && 'custom_post' == $queried_post_type ) { $redirection_url = get_site_url() . '/custom_page'; wp_redirect( $redirection_url, 301 ); exit; } }
Get WooCommerce order information like billing, shipping & date.
$order_id = 1234; $order_data = new WC_Order($order_id); //Order Date $order_date = $order_data->order_date; //Billing information $billing = $order_data->get_address('billing'); //Shipping information $shipping = $order_data->get_address('shipping');
Get WordPress dynamic URL in JS file
//Include JS file wp_enqueue_script('js_file', plugins_url('assets/js/js_file.js', __FILE__), array('jquery'), false); wp_localize_script( 'js_file', 'WPURLS', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )); // JS file var url = WPURLS.ajax_url;
How to allow break tag in EXCEL file using php
require_once "xlsxwriter.class.php"; $writer = new XLSXWriter(); $writer->writeSheetRow('Sheet1', $row, $row_options = array('wrap_text'=>true));
Get all WooCommerce processing and completed order.
global $wpdb; $orders = $wpdb->get_results( "SELECT ID FROM {$wpdb->prefix}posts WHERE post_type = 'shop_order' AND post_status in ('wc-completed', 'wc-processing')");
Button flash using CSS3
.flash-button{
background:#cc0000;
color:#fff;
border: 1px solid #cc0000;
border-radius: 6px;
animation-name: flash;
animation-duration: 1s;
animation-timing-function: linear;
animation-iteration-count: infinite;
-webkit-animation-name: flash;
-webkit-animation-duration: 1s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-moz-animation-name: flash;
-moz-animation-duration: 1s;
-moz-animation-timing-function: linear;
-moz-animation-iteration-count: infinite;
}
@keyframes flash {
0% { opacity: 1.0; }
50% { opacity: 0.5; }
100% { opacity: 1.0; }
}
@-webkit-keyframes flash {
0% { opacity: 1.0; }
50% { opacity: 0.5; }
100% { opacity: 1.0; }
}
@-moz-keyframes flash {
0% { opacity: 1.0; }
50% { opacity: 0.5; }
100% { opacity: 1.0; }
}
WordPress posts_per_page does not work
Use below code. $web = array( 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'nopaging' => true, 'post_type' => 'product' ); $query = new WP_Query( $web );