Month: May 2016

Remove text editor for custom post type in WordPress

For our customization want to remove text editor for custom post type then place the following snippet in functions.php within your theme folder!.

function remove_text_editor_custom_post_type() {
    remove_post_type_support( 'post_type_name', 'editor' );
}
add_action('init', 'remove_text_editor_custom_post_type');

Have any doubt, then comment here!

Get woocommerce cart count in WordPress

For our customization want to get the count of number of products in a cart then use the following code.

global $woocommerce;
$count = $woocommerce->cart->cart_contents_count;
if ($count > 0) 
{
	echo $count;
}
else
{
 echo "No products in cart";
}

Have any doubt, then comment here!

Create widget in WordPress programmatically

For our customization want to create a new widget in WordPress programmatically then place the following snippet in functions.php within your theme folder!.

add_action( 'widgets_init', 'create_new_widget' );
function create_new_widget() 
{
    register_sidebar( array(
        'name' => __( 'Custom Sidebar', 'theme-slug' ),
        'id' => 'custom_sidebar',
        'description' => __( 'Your widget description here', 'theme-slug' ),       
    ) );
}

After that you can call this sidebar by following code. Wherever you want add the following code in that particular place.

dynamic_sidebar( 'left-sidebar' );

Have any doubt, then comment here!

Change order note label in woocommerce checkout page

For our customization want to change woocmmerce order notes label in checkout page then place the following snippet in functions.php within your theme folder!.

add_filter( 'woocommerce_checkout_fields' , 'change_order_note_label_in_woocommerce_checkout_page' );
function change_order_note_label_in_woocommerce_checkout_page( $fields ) {
     $fields['order']['order_comments']['label']="Special Insructions";
     return $fields;
}

Have any doubt, then comment here!

Change woocmmerce out of stock text in wordpress

For our customization want to change woocommerce Out of stock text to Sold Out then place the following snippet in functions.php within your theme folder!.

add_filter('woocommerce_get_availability', 'change_woocommerce_out_of_stock_text');
function change_woocommerce_out_of_stock_text($availability)
{
	$availability['availability'] = str_ireplace('Out of stock', 'Sold Out', $availability['availability']);
	return $availability;
}

Have any doubt, then comment here!