Skip to content

Instantly share code, notes, and snippets.

View elias1435's full-sized avatar
🕋
Working from home

Md. Elias elias1435

🕋
Working from home
View GitHub Profile
@elias1435
elias1435 / package.json
Created December 11, 2023 15:59 — forked from hasinhayder/package.json
Shopify App Extension with Local Script
{
"name": "faq-laravel",
"private": true,
"license": "UNLICENSED",
"scripts": {
"shopify": "shopify",
"build": "shopify app build",
"dev": "shopify app dev",
"info": "shopify app info",
"scaffold": "shopify app generate extension",
@elias1435
elias1435 / functions.php
Created August 21, 2023 16:50
WooCommerce Mini Cart is coming Blank on add to cart from product page. code will do under functions.php make sure you are using child theme.
function enqueue_wc_cart_fragments() {
wp_enqueue_script( 'wc-cart-fragments' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_wc_cart_fragments' );
@elias1435
elias1435 / functions.php
Created August 17, 2023 15:47
How to display acf product field in woocommerce order email. ACF field name is 'customer_email' and its location is product. blow code will go to functions.php
add_action( 'woocommerce_order_item_meta_end', 'custom_product_info', 20, 4 );
function custom_product_info ( $item_id, $item, $order, $plain_text ) {
$id = $item->get_product_id();
$product_info = get_field('customer_email',$id);
if($product_info){
echo "<p>Customer Message: $product_info</p>";
}}
@elias1435
elias1435 / add_to_cart_when_match_category.php
Created August 1, 2023 10:41
If you want to redirect after add to cart product only for selected category for this example category is 'main-category' use this below code to functions.php
function custom_add_to_cart_redirect( $url ) {
global $woocommerce;
// Retrieve the product ID from the 'add-to-cart' request parameter.
$product_id = isset( $_REQUEST['add-to-cart'] ) ? intval( $_REQUEST['add-to-cart'] ) : 0;
// Check if the product ID is valid and if the category name is 'main-product'.
if ( $product_id > 0 && has_term( 'main-product', 'product_cat', $product_id ) ) {
// The URL you want to redirect to for 'main-product'.
$redirect_url = 'https://yourdomain.com/add_your_url_here';
@elias1435
elias1435 / add-body-class-wordpress_functions.php
Created June 16, 2023 12:16
How to Add Category Id to WordPress Body and Post Class This snippet is very handy if you wish to add category ID to WordPress body and post class for ex. targeting CSS styles and such.
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes [] = 'cat-' . $category->cat_ID . '-id';
//if you want to add category slug replace below code
//$classes [] = 'cat-' . $category->slug;
return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');
@elias1435
elias1435 / functions.php
Created May 2, 2023 07:15
Add Widget option wordpress - Functions.php
if (function_exists("register_sidebar")) {
register_sidebar();
}
@elias1435
elias1435 / single.php
Created February 24, 2023 10:05
Custom Post Type Related Posts to Your WordPress Site Without Plugins. All the codes need to add in your single.php add this code snippet after the post loop end.
$related = new WP_Query(
array(
'post_type' => 'tutorials', //YOUR CPT SLUG
'category__in' => wp_get_post_categories( $post->ID ),
'posts_per_page' => 3,
'post__not_in' => array( $post->ID ),
)
);
if ( $related->have_posts() ) { ?>
@elias1435
elias1435 / functions.php
Created February 16, 2023 18:28
How to reorder checkout fields on WooCommerce checkout billing or shipping firleds
add_filter( "woocommerce_checkout_fields", "my_reordering_checkout_fields", 15, 1 );
function my_reordering_checkout_fields( $fields ) {
## ---- Billing Fields ---- ##
// Set the order of the fields
$billing_order = array(
'billing_first_name',
'billing_last_name',
'billing_email',
'billing_phone',
'billing_company',
@elias1435
elias1435 / functions.php
Created February 14, 2023 14:53
Remove the vertical bar | in the various action nav groups on Membership Account, Log In widget, and more.
<?php
/**
* Remove the vertical bar | in the various action nav groups on Membership Account, Log In widget, and more.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
*/
@elias1435
elias1435 / Remove <p> Tag From Contact Form 7
Created January 5, 2023 11:04
The filter need to add to your wordpress theme functions.php
// removed cf7 <p> tag
add_filter('wpcf7_autop_or_not', '__return_false');