Tuesday, 2 May 2023

How to hide PHP Warnings and Notices in WordPress

 Add the below line in wp-config.php

ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);

Checking the pincode of shipping and adding in assigning to fulfilment-partner

 // Checking the pincode of shipping and adding in assigning to fulfilment-partner
function before_checkout_create_order($order, $data)
{
    $args1 = array('role__in' => array('fulfilment_partner') );    
    $shipping_pincode = $order->shipping_postcode;
    $users = get_users( $args1 );        

    // Array of WP_User objects.
    foreach ( $users as $user ) {
        $stpax = explode(',',trim($user->stokist_pincode_allocated));
        if (in_array($shipping_pincode,$stpax)) {             
            $store_manager_id = $user->id ;            
        }        
    }         
    $order->update_meta_data('_store_manager_id', $store_manager_id);    
}
add_action('woocommerce_checkout_create_order', 'before_checkout_create_order', 20, 2);

//Showing the order according to fulfilment partner wise.
function custom_admin_shop_manager_orders($query)
{
    global $pagenow;
    $qv = &$query->query_vars;
    $currentUserRoles = wp_get_current_user()->roles;
    $user_id = get_current_user_id();    
    //if (in_array('shop_manager',$currentUserRoles)) {        
    if($currentUserRoles[0] == 'fulfilment_partner')
    {
    
        if ( $pagenow == 'edit.php' &&     isset($qv['post_type']) && $qv['post_type'] == 'shop_order' ) {
            // I use the meta key from step 1 as a second parameter here
            $query->set('meta_key', '_store_manager_id');
            // The value we want to find is the $user_id defined above
            $query->set('meta_value', $user_id);
        }
    }

    return $query;
}
add_filter('pre_get_posts', 'custom_admin_shop_manager_orders');

Show extra field in profile

 //Pincode starts here.
add_action( 'show_user_profile', 'show_extra_profile_fields' );
add_action( 'edit_user_profile', 'show_extra_profile_fields' );

function show_extra_profile_fields( $user ) {
    if(is_user_logged_in() ) {
        $user = wp_get_current_user();
        $user->roles[0];
        if ($user->roles[0] == 'administrator') { ?>    
            <table class="form-table">
                <tr>
                    <th><label for="contact">Pincode Assigned</label></th>
                    <td>                
                        <textarea  name="stokist_pincode_allocated" id="stokist_pincode_allocated" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'stokist_pincode_allocated', $user->ID ) ); ?></textarea><br />
                        <span class="description">Please enter your Pincode.</span>
                    </td>
                </tr>
            </table>
<?php } } }
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );

function save_extra_profile_fields( $user_id ) {
    if ( ! current_user_can( 'edit_user', $user_id ) ) {
        return false;
    }
    update_usermeta( $user_id, 'stokist_pincode_allocated', esc_attr( $_POST['stokist_pincode_allocated'] ) );
}

Removing extra fields from profile page. User description, outlet, address, url

 //Removing extra fields from profile page. User description, outlet, address, url
function remove_website_row_wpse(){
    echo '<style>tr.user-url-wrap{ display: none; }</style>';
    echo '<style>tr.user-description-wrap{ display: none; }</style>';
    echo '<style>tr.OutletName{ display: none; }</style>';
    echo '<style>tr.Address{ display: none; }</style>';
}
add_action( 'admin_head-user-edit.php', 'remove_website_row_wpse' );
add_action( 'admin_head-profile.php',   'remove_website_row_wpse' );

Removing extra field name company from checkout page.

 //Removing extra field name company from checkout page.
function remove_company_name_from_checkout( $fields ) {
    unset( $fields['billing_company'] );
    return $fields;
}
add_filter( 'woocommerce_billing_fields', 'remove_company_name_from_checkout' );

Monday, 1 January 2018

Steps to create wordpress theme.

Below are the steps to create new theme.
Step1. Create a folder in wp-content/themes/ and name the folder.

Step2. Take a screenshot of the html and put it in the theme folder and name is screenshot.png

Step3. Create a style.css file and put the below code.
/*
Theme Name: Your theme Name
Theme URI: https://wordpress.org/themes/twentyfifteen/
Author: the WordPress team
Author URI: https://wordpress.org/
Description: Description of theme.
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, blue, gray, pink, purple, white, yellow, dark, light, two-columns, left-sidebar, fixed-layout, responsive-layout, accessibility-ready, custom-background, custom-colors, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, threaded-comments, translation-ready
Text Domain: twentyfifteen
*/

Step4. Create functions.php , header.php and footer.php file.
In the header file write this code.
      <?php wp_head(); ?>
And in footer file write this code above </body> tag.
    <?php wp_footer(); ?>

Step5. Include custom css and js files in theme
function add_theme_scripts() {
  wp_enqueue_style( 'style', get_stylesheet_uri() );
   wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css', array(), '1.1', 'all');
   wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);

}
//add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
For theme setup.

if ( ! function_exists( 'mytheme_setup' ) ) :
function mytheme_setup() {
register_nav_menus( array(
        'primary'   => __( 'Primary Menu', 'mytheme' ),
        'secondary' => __('Secondary Menu', 'mytheme' )
    ) );


add_theme_support( 'post-thumbnails' );

}
endif;
add_action( 'after_setup_theme', 'mytheme_setup' );
*******************************************************
Adding a custom logo.

function themename_custom_logo_setup() {
    $defaults = array(
        'height'      => 100,
        'width'       => 400,
        'flex-height' => true,
        'flex-width'  => true,
        'header-text' => array( 'site-title', 'site-description' ),
    );
    add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
*******************************************************


function themename_custom_header_setup() {

    $args = array(
        'default-image'      => get_template_directory_uri() . 'img/default-image.jpg',
        'default-text-color' => '000',
        'width'              => 1000,
        'height'             => 250,
        'flex-width'         => true,
        'flex-height'        => true,
    )
    add_theme_support( 'custom-header', $args );
}
add_action( 'after_setup_theme', 'themename_custom_header_setup' );
*******************************************************
  
Step.7 Whenever you create any page include get_header();  and get_footer();

 Creating custom page template.
<?php /* Template Name: CustomPageT1 */ ?>

Use below url for more information:
https://developer.wordpress.org/themes/functionality/








Friday, 5 August 2016

How to change the post menu and options.


function change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = 'Articles';
$submenu['edit.php'][5][0] = 'Articles';
$submenu['edit.php'][10][0] = 'Add New';
$submenu['edit.php'][15][0] = 'Cat';
$submenu['edit.php'][16][0] = 'Tags';
}
add_action( 'admin_menu', 'change_post_menu_label' );

Thursday, 7 July 2016

How to display multiple featured images

Dynamic featured image

Use dynamic featured image plugin for multiple featured images.
Copy the below code in your template or content-page.php file. You will have multiple images.

<div class="post-thumbnail">
  <?php  
           if( class_exists('Dynamic_Featured_Image') )
           {
             global $dynamic_featured_image;
             $featured_images = $dynamic_featured_image->get_featured_images();
            }   
               //echo "<pre>";print_r($featured_images);
            $attachment_cnt = count($featured_images);
            for($i=0;$i<$attachment_cnt;$i++)
            { ?><img src="<?php echo $featured_images[$i]['full'];?>" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" style="margin-bottom:10px;"><?php } ?>
  </div>

Thursday, 24 March 2016

What is zerofill attribute.

When used in conjunction with the optional (nonstandard) attribute ZEROFILL,
the default padding of spaces is replaced with zeros. For example, for a column declared as INT(4) ZEROFILL,
a value of 5 is retrieved as 0005.

What is the difference between MYISM and INNODB

MYISAM:
1. MYISAM supports Table-level Locking
2. MyISAM designed for need of speed
3. MyISAM does not support foreign keys and relationship constraints
4. MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
5. MYISAM does not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done.


INNODB:
1. InnoDB supports Row-level Locking
2. InnoDB designed for maximum performance when processing high volume of data
3. InnoDB support foreign keys and relationship constraints
4. InnoDB stores its tables and indexes in a tablespace
5. InnoDB supports transaction. You can commit and rollback with InnoDB