Enable AJAX Submit in GravityForms in wordpress

Enable AJAX Submit in GravityForms in wordpress

To enable AJAX form submission in Gravity Forms on your WordPress site, simply navigate to the form settings and enable the AJAX option.

This allows users to submit forms without a page reload, enhancing user experience and improving performance. To activate AJAX, use the shortcode [gravityform id="1" ajax="true"], replacing "1" with your actual form ID.

Alternatively, if adding the form via PHP, use gravity_form(1, false, false, false, '', true);.

Enabling AJAX ensures smoother interactions, reduces page load times, and provides instant feedback, making it ideal for modern, dynamic websites.

How to enable error reporting in Magento2

How you can enable error reporting in magento2 :

Connect FTP OR login into cpanel account and go to the following directory

pub/errors

find the local.xml.sample and rename to local.xml

and also on magento root folder find index.php and put the display error code at the bottom

error_reporting(E_ALL);
ini_set(‘display_errors’, 1);

Change woocommerce price position

If want to change the position of the price in wocommerce then this is possible. You can it easy in adding little code in the functions.php file.

If you want to put price near add to cart button then please add following code to Functions.php file of your child theme (or parent theme, if not using a child theme)- you can use Dashboard -> Appearance > Editor or direct FTP

remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 29 );

How to override .phtml files in Magento 2

Here is tips for how to override .phtml files in Magento 2. Please follow below steps

vendor/vendor/magento/module-checkout/view/frontend/templates/onepage.phtml

Follow this path

app/design/frontend/Vendor/theme/Magento_Checkout/templates/onepage.phtml

Show only single category posts on WordPress archive page

To display only a single category’s posts on a WordPress archive page, you can modify your theme’s functions.php file or create a custom template. The best approach is to use the pre_get_posts hook, which allows you to filter the query before WordPress retrieves posts. Here’s an optimized way to do it:

function filter_archive_by_category( $query ) {
if ( !is_admin() && $query->is_archive() && $query->is_main_query() ) {
$query->set( 'cat', 12 ); // Replace 12 with your category ID
}
}
add_action( 'pre_get_posts', 'filter_archive_by_category' );

This snippet ensures that only posts from a specific category appear on archive pages while maintaining performance and compatibility. You can replace the category ID (12) with the desired category’s ID, which can be found in the WordPress admin panel under Posts > Categories. This method is ideal for keeping your theme lightweight and SEO-friendly without modifying core files.

Magento2 admin account disabled error

Magento2 admin account disabled error:

Hello All,

If you get issue something below on the Magento2 login page

 

 

Simply below query to database via phpmyadmin.

Example is for reset password for admin user.

UPDATE admin_user SET password = CONCAT(SHA2(‘xxxxxxxxNewPassword’, 256), ‘:xxxxxxxx:1’) WHERE username = ‘admin’;

NewPassword : Replace it with your password.

 

Hope it will work.

Get Magento catalog image

Today  I will show you how you can get the magento catalog image via code on any page. Please use below code and you will be done!!

 

Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(100);

Exclude a category id from category collection in Magento

Please use the below code for exclude a category id from category collection in Magento

<?php
      $allCategories = Mage::getModel('catalog/category')
                       ->getCollection()
                       ->addAttributeToSelect('*')
                       ->addAttributeToFilter('level',2)
                       ->addAttributeToFilter('entity_id', array('nin' => 69))
                       ->addIsActiveFilter(); 

?>

Get Categories and Its Sub Categories in Magento

Get Categories and Its Sub Categories in Magento:

To retrieve categories and their subcategories in Magento, you can use Magento’s built-in repository classes and helper functions. Using the Magento\Catalog\Model\CategoryRepository and Magento\Catalog\Model\ResourceModel\Category\CollectionFactory, you can efficiently fetch category data, including subcategories, in a structured way. Here’s a basic approach:

use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
use Magento\Framework\App\State;

class CategoryHelper
{
protected $categoryCollectionFactory;

public function __construct(
CollectionFactory $categoryCollectionFactory,
State $state
)
{
$this->categoryCollectionFactory = $categoryCollectionFactory;
$state->setAreaCode('frontend'); // Required if running in non-frontend context
}

public function getCategoriesWithSubcategories()
{
$categories = $this->categoryCollectionFactory->create()
->addAttributeToSelect(['name', 'is_active'])
->addAttributeToFilter('is_active', 1)
->setOrder('position', 'ASC');

$categoryData = [];
foreach ($categories as $category) {
if ($category->getParentId() == 2) { // Root category check
$subCategories = [];
foreach ($categories as $subCategory) {
if ($subCategory->getParentId() == $category->getId()) {
$subCategories[] = ['id' => $subCategory->getId(), 'name' => $subCategory->getName()];
}
}
$categoryData[] = [
'id' => $category->getId(),
'name' => $category->getName(),
'subcategories' => $subCategories
];
}
}
return $categoryData;
}
}

This method ensures that only active categories are retrieved, sorted in the desired order, and structured to include their subcategories efficiently. This approach is optimal for displaying category navigation menus, filters, or hierarchical category structures in Magento stores.

How to Remove SID query from Magento URLs

We will apply the site redirects technique for this issue . While working on the SEO someone can place a wrong link to some forum or blog. We don’t want those links to lead to improper URL and we don’t want SIDs to appear to those visitors. Most important: We don’t want that search engines index the URLs with SIDs.

The solution is simple.

For magento1 you will have to go to root directory .htacess file and add the below code and in Magento2 you should write the code in the pub directory .htaccess file.

RewriteEngine on
If you want to have www part:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
If you don’t want to have www part:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]