Latest Questions

  • 2.11 Years

    • Category : Wordpress
    • Location : Chandigarh, India
    • Posted On : Feb 13, 2019

    Disable default wp-cron.php behavior We can easily tell WordPress to let us handle the execution of wp-cron.php with the wp-config.php file.

    Open your wp-config.php file with the cPanel File Manager Code Editor
    
    Go to the bottom of the database settings in wp-config.php.
    define( 'AUTOSAVE_INTERVAL',    3600 );     // autosave 1x per hour
    define( 'WP_POST_REVISIONS',    false );    // no revisions
    define( 'DISABLE_WP_CRON',      true );
    define( 'EMPTY_TRASH_DAYS',     7 );        // one week
    
    Now WordPress will not automatically run the wp-cron.php script each time your site gets a new visitor.
  • 2.11 Years

    • Category : Jquery
    • Location : Chandigarh, India
    • Posted On : Feb 4, 2019

    If you want to create a web page form like contact form or any other form text field. if you want to allow only numeric letters like (0-9)

    <input name="number">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <script type="text/javascript">
    // Numeric only control handler
    jQuery.fn.ForceNumericOnly =
    function()
    {
        return this.each(function()
        {
            $(this).keydown(function(e)
            {
                var key = e.charCode || e.keyCode || 0;
                // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
                // home, end, period, and numpad decimal
                return (
                    key == 8 || 
                    key == 9 ||
                    key == 13 ||
                    key == 46 ||
                    key == 110 ||
                    key == 190 ||
                    (key >= 35 && key <= 40) ||
                    (key >= 48 && key <= 57) ||
                    (key >= 96 && key <= 105));
            });
        });
    };
    $('input[name="number"]').ForceNumericOnly();
    </script>
  • 2.11 Years

    • Category : Yii2
    • Location : Chandigarh, India
    • Posted On : Feb 4, 2019

    If you just want to remove packages or extension from the vendor directory you can use composer command:

    composer remove package/name

    For Example:

    composer require 2amigos/yii2-ckeditor-widget (for Installation)
    composer remove 2amigos/yii2-ckeditor-widget (for remove)
  • 5.11 Years

    • Category : Yii2
    • Location : Mohali
    • Posted On : Feb 4, 2019

    This is how to use Gii working on remote server for an yii2 advanced template.

    This is how to use Gii working on remote server for an yii2 advanced template.

    In the frontend config file. Example:

    (your folder)/frontend/config/main-local.php

    Add the following code:
    
    if (!YII_ENV_TEST) {
        // configuration adjustments for 'dev' environment
        $config['bootstrap'][] = 'debug';
        $config['modules']['debug'] = 'yii\debug\Module';
    
        $config['bootstrap'][] = 'gii';
        $config['modules']['gii']=[
          'class' =>  'yii\gii\Module',
          'allowedIPs' => ['<enter your id address>'],  // open https://www.dorcode.com/ip-locator-with-google-map link for your ip address
        ];
    }
    Then open (your folder)/frontend/gii

    In the Backend config file. Example:

    (your folder)/backend/config/main-local.php

    Add the following code:
    
    if (!YII_ENV_TEST) {
        // configuration adjustments for 'dev' environment
        $config['bootstrap'][] = 'debug';
        $config['modules']['debug'] = 'yii\debug\Module';
    
        $config['bootstrap'][] = 'gii';
        $config['modules']['gii']=[
          'class' =>  'yii\gii\Module',
          'allowedIPs' => ['<enter your id address>'],  // open https://www.dorcode.com/ip-locator-with-google-map link for your ip address 
        ];
    }
    
    Then open (your folder)/backend/gii

    Open https://www.dorcode.com/ip-locator-with-google-map click here for your ip address

  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Feb 4, 2019

    After doing all the settings of (https://github.com/akiraz2/yii2-ticket-support/blob/HEAD/docs/getting-started.md) link, you do this:

    1) open your yii directory path '@vendor\akiraz2\yii2-ticket-support\Module.php' file and go to line no. 75:
    
        'imap' => [
            'host' => 'imap.site.com', // enter your email host name. if your hosting on godaddy then some time your host is 'imap.yourdomain.com'; 
            'username' => 'support@site.com', // enter email address
            'password' => '123456789879', // enter your email password
        ]
    
        //public $imap = [];
    
    
    2) and then open https://github.com/akiraz2/yii2-ticket-support/blob/HEAD/docs/README.md link and follow up.
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Sep 9, 2018

    Customer session does not work except some pages

    Method 1.  To check if customer is logged: (best way)Create helper file like Data.phphow to create custom helper or module https://www.dorcode.com/blog/52/how-to-create-and-use-helpers-in-magento-2


    <?php
    namespace Magento\Mytheme\Helper;
    
    class Data extends \Magento\Framework\App\Helper\AbstractHelper
    {
        protected $_customerSession;
        protected $_customerSessionn;
    
        public function __construct(\Magento\Framework\App\Helper\Context $context,
                \Magento\Framework\App\Request\Http $request,
                \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
                \Magento\Customer\Model\SessionFactory $customerSession,
                \Magento\Customer\Model\Session $customerSessionn
            ) 
        {
            $this->request = $request;
            $this->customerRepository = $customerRepository;
            $this->_customerSession = $customerSession;
            $this->_customerSessionn = $customerSessionn;
            parent::__construct($context);
        }
        public function getCustomerName(){
            $customer = $this->_customerSession->create();
            return $customer->getCustomer()->getName();
        }
        public function isLoggedIn()
        {
            return $this->_customerSessionn->isLoggedIn();
        }
    }
    ?>
    
    Call to your template :
    
    <?php
    $myhelper = $this->helper('Magento\Mytheme\Helper\Data');
    $cname=$myhelper->getCustomerName();
    $isLoggedIn=$myhelper->isLoggedIn();
    
    if ($isLoggedIn):
    	   echo 'login';
    else : 
    	  echo 'not login';
    endif;
    ?>
  • 5.11 Years

    • Category : Java
    • Location : Mohali
    • Posted On : Aug 8, 2018

    Here are two scenarios where the keyup event will not get fired: The user drags text into the textarea. The user copy-paste text in the textarea with a right click (contextual menu).

    Use the HTML5 input event instead for a more robust solution:

    // jquery
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    
    // html
    <div class="control">
    	<textarea spellcheck="true" maxlength="200" name="question" id="question" class="input-textarea required-entry" cols="5" rows="8" data-validate="{required:true}" aria-required="true"></textarea>
      <div class="limittext"><span class="charnum">200 Characters left</span></div>
    </div>
    
    <script type="text/javascript">
    jQuery(document).ready(function() {
      // edit area start
      var maxLength = 200;
      var textarea_id = "question";
      // edit area end
    
      var html='<span style="color:red;">'+ maxLength + ' characters allowed, excess characters trimmed</span>';
      jQuery("#"+textarea_id).on('input',function(){
          var length = this.value.length;
          if (length >= maxLength) {
            this.value = this.value.substring(0, maxLength);
            jQuery(this).next(".limittext").html(html);
          } else {
            var count=maxLength-length;
            jQuery(this).next(".limittext").html('<span class="charnum">' +count+' Characters left</span>');
          }
      });
    });
    </script>
  • 5.11 Years

    • Category : Magento
    • Location : Mohali
    • Posted On : Jul 26, 2018

    Customer session does not work except some pages

    Method 1.  To check if customer is logged: (best way)
    Create helper file like Data.php

    how to create custom helper or module https://www.dorcode.com/blog/52/how-to-create-and-use-helpers-in-magento-2
     
    <?php
    namespace Magento\Mytheme\Helper;
    
    class Data extends \Magento\Framework\App\Helper\AbstractHelper
    {
        protected $_customerSession;
        protected $_customerSessionn;
    
        public function __construct(\Magento\Framework\App\Helper\Context $context,
                \Magento\Framework\App\Request\Http $request,
                \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
                \Magento\Customer\Model\SessionFactory $customerSession,
                \Magento\Customer\Model\Session $customerSessionn
            ) 
        {
            $this->request = $request;
            $this->customerRepository = $customerRepository;
            $this->_customerSession = $customerSession;
            $this->_customerSessionn = $customerSessionn;
            parent::__construct($context);
        }
        public function getCustomerName(){
            $customer = $this->_customerSession->create();
            return $customer->getCustomer()->getName();
        }
        public function isLoggedIn()
        {
            return $this->_customerSessionn->isLoggedIn();
        }
    }
    ?>
    
    Call to your template :
    
    <?php
    $myhelper = $this->helper('Magento\Mytheme\Helper\Data');
    $cname=$myhelper->getCustomerName();
    $isLoggedIn=$myhelper->isLoggedIn();
    
    if ($isLoggedIn):
    	   echo 'login';
    else : 
    	  echo 'not login';
    endif;
    ?>
    Method 2. To check the customer is logged or not on any page of the website:
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    
    $customerSession = $objectManager->get('Magento\Customer\Model\Session');
    
    if($customerSession->isLoggedIn()) {
    
       // customer login action
    
    }
     
  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : May 29, 2018

    To disable this update notification, there is no switch in the settings menu or anywhere else in the admin dashboard. To prevent WordPress from showing these information snippets on top of your WordPress dashboard, you shall need to add a PHP code snippet to your functions.php file.

    add_filter('pre_site_transient_update_core','__return_null');
    add_filter('pre_site_transient_update_plugins','__return_null');
    add_filter('pre_site_transient_update_themes','__return_null');
     
  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : May 29, 2018

    default WooCommerce if the user clicks on the add to cart button, that item is added to the cart. if you want to add custom add to cart button please remove default "add to cart" button

    // custom template
    <button type="submit" class="custom_cart_button">add to cart</button>
    <script type="text/javascript">
    jQuery(document).ready(function() {
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
        jQuery('.custom_cart_button').submit(function(e) {
            jQuery.ajax({
                url: ajaxurl,
                type: "post",
                data: {				
    		action : 'post_product_variations19'
    	    },
                success: function(data) {   
                	console.log(data);
                }
            });
    	return false;
        });
    });
    </script>
    
    
    // function.php
    add_action( 'wp_ajax_nopriv_post_product_variations19', 'post_product_variations_func19' );
    add_action( 'wp_ajax_post_product_variations19', 'post_product_variations_func19' );
    function post_product_variations_func19() {
    
        global $woocommerce;
    
        $product_id = 364; // your product id
    
        $found = false;
    
        //check if product already in cart
        if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
            foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id ) {
                	//$calc_qty = $values['quantity'] < 1 ? 1 : $values['quantity']+1;
                	//$woocommerce->cart->set_quantity( $cart_item_key, $calc_qty, true );
                    $found = true;
                }
            }
            // if product not found, add it
            //if ( ! $found )
                $woocommerce->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            $woocommerce->cart->add_to_cart( $product_id );
        }
    	
    wp_die();
    }
More Questions...