Skip to content

Instantly share code, notes, and snippets.

View navnit-viradiya's full-sized avatar

Navnit Viradiya navnit-viradiya

View GitHub Profile
@navnit-viradiya
navnit-viradiya / help-magento
Last active July 12, 2025 07:49
help-magento
php bin/magento config:set catalog/search/engine elasticsearch7
php bin/magento config:set catalog/search/elasticsearch7_server_hostname localhost
php bin/magento config:set catalog/search/elasticsearch7_server_port 9200
php bin/magento config:set web/unsecure/base_url https://www.test.de/
php bin/magento config:set web/secure/base_url https://www.test.de/
Create admin user
-----------------
php bin/magento admin:user:create --admin-user=navnit --admin-password=test@123 [email protected] --admin-firstname=born --admin-lastname=QA
@navnit-viradiya
navnit-viradiya / Magento 2 patch create and apply
Created July 12, 2025 06:52
Magento 2 patch create and apply
Step 1:
File to changed should be added to the git
git add -f vendor/dotmailer/dotmailer-magento2-extension/Api/Data/CouponAttributeInterface.php
Step 2:
Then make the changes to the core file
Step 3:
After making the changes run
git diff vendor/dotmailer/dotmailer-magento2-extension/Api/Data/CouponAttributeInterface.php > m2-hotfixes/webapi-fix.patch
@navnit-viradiya
navnit-viradiya / functions.php
Created April 30, 2019 10:43
WooCommerce - Add a special field to the checkout, order emails and user/order meta or Load specific custom fields on change country.
<?php
add_action('woocommerce_review_order_before_payment', 'gst_checkout_field');
function gst_checkout_field( $checkout ) {
echo '<div id="gst_checkout_field_sec">';
woocommerce_form_field( 'gst_no', array(
'type' => 'text',
'class' => array('my-field-class orm-row-wide'),
'label' => __('GST No'),
@navnit-viradiya
navnit-viradiya / functions.php
Created April 16, 2019 07:44
Get the right prev/next post link when order posts by menu_order
<?php
function my_previous_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
add_filter( 'get_previous_post_where', 'my_previous_post_where' );
function my_next_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order > %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
@navnit-viradiya
navnit-viradiya / wp-query-with-meta-query-and-taxonomy.php
Created September 27, 2018 10:23
WooCommerce search products between price range using WP_Query
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array (
'taxonomy' => 'product_cat',
'field' => 'slug',
@navnit-viradiya
navnit-viradiya / wp-query-with-custom taxonomy.php
Created September 27, 2018 08:07
Wp_query with a custom taxonomy.
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array (
'taxonomy' => 'product_cat',
'field' => 'slug',
@navnit-viradiya
navnit-viradiya / wp-query-with-meta-query.php
Created September 27, 2018 07:56
Wp_query example for meta query with multiple meta field.
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
/*'meta_key' => 'ingredients',
'meta_value' => ' ',
'meta_compare' => '!='*/
'meta_query' => array(
'relation' => 'AND',
@navnit-viradiya
navnit-viradiya / faq-example.html
Created September 7, 2018 13:04
FAQ Page with Show and Hide Questions and Answers. Showing First Question Answer on Page Load.
<!DOCTYPE html>
<html>
<head>
<title>faq</title>
<style>
/*FAQS*/
.faq_question {
@navnit-viradiya
navnit-viradiya / character-limit.php
Created August 30, 2018 11:28
Set character limit on get_the_content() or get_the_excerpt() in wordpress
<?php
function break_content($text,$length){
$text = trim($text);
if(strlen($text)<$length+10)
return $text;//don't cut if too short
$break_pos = strpos($text, ' ', $length);//find next space after desired length
$visible = substr($text, 0, $break_pos);
<?php
//Show post category wise shortcode [show_post_category_wise]
add_shortcode('show_post_category_wise','show_post_category_wise_shortcode');
function show_post_category_wise_shortcode(){
$terms = get_terms('category');
$html = '';
if($terms) {
foreach($terms as $term){