Stay up to date

WITH OUR BLOG

Add payment gateway for certain users only

add_filter( ‘woocommerce_available_payment_gateways’, ‘hide_payment_gateway’ ); function hide_payment_gateway( $available_gateways ) { global $woocommerce; if ( isset( $available_gateways[‘cod’] ) && !current_user_can(‘administrator’) && !current_user_can(‘staff’) && !current_user_can(‘editor’) ) { unset( $available_gateways[‘cod’] ); } return $available_gateways; }

Custom columns content

add_action( ‘manage_colourmedia_column’, ‘colourmedia_columns’, 10, 2 ); function manage_colourmedia_columns( $column, $post_id ) { global $post; $terms = get_post_meta( $post_id ); switch( $column ) { case ‘thumbnail’ : $url = get_the_post_thumbnail_url($post_id); printf( ‘<img src=”‘.$url.'” style=”width:100px”/>’ ); break; case ‘city’ : printf($terms[‘City’][0]); break; case ‘category’ : $cat_list = wp_get_post_terms($post->ID, ‘category’, array(“fields” => “names”)); foreach($cat_list as &$category){ echo ‘<a […]

Custom backend post list columns

add_filter( ‘manage_edit-colourmedia_columns’, ‘colourmedia_columns’ ) ; // init function function colourmedia_columns( $columns ) { $columns = array( ‘cb’ => ‘&lt;input type=”checkbox” />’, ‘thumbnail’ => __( ‘Thumbnail’ ), ‘category’ => __( ‘Category’ ), ‘title’ => __( ‘Name’ ), ‘city’ => __( ‘City’ ), ‘featured’ => __( ‘Featured’ ), ); return $columns; }

Register custom post type

function colourmedia_post_type() { $args = array( ‘public’ => true, ‘label’ => __( ‘BackendName’, ‘textdomain’ ), ‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘comments’, ‘custom-fields’ ), ‘menu_icon’ => ‘dashicons-megaphone’, ); register_post_type( ‘colourmedia’, $args ); } add_action( ‘init’, ‘colourmedia_post_type’ );