Skip to content

Instantly share code, notes, and snippets.

@rabinkumarpal
rabinkumarpal / gist:581af2cb9ca53725240c0de5702ad4c0
Last active August 26, 2022 09:09 — forked from stereokai/gist:36dc0095b9d24ce93b045e2ddc60d7a0
CSS rounded corners with gradient border
.rounded-corners-gradient-borders {
width: 300px;
height: 80px;
border: double 4px transparent;
border-radius: 80px;
background-image: linear-gradient(white, white), radial-gradient(circle at top left, #f00,#3020ff);
background-origin: border-box;
background-clip: content-box, border-box;
}
@rabinkumarpal
rabinkumarpal / countries
Created September 15, 2022 06:28 — forked from kalinchernev/countries
Plain text list of countries
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua & Deps
Argentina
Armenia
Australia
Austria
@rabinkumarpal
rabinkumarpal / functions.php
Created September 25, 2022 16:06 — forked from MWDelaney/functions.php
WooCommerce: Prevent multiple coupons of the same "type" on a single order. This will, for instance, prevent coupon stacking if a customer or user has access to multiple Product % Discount or Cart % Discount coupons. Tested working with WooCommerce, WooCommerce Smart Coupons, and WooCommerce Points & Rewards
<?php
// Hook when a coupon is applied to a cart
add_action( 'woocommerce_applied_coupon', 'mwd_get_applied_coupons' );
// Get the current applied coupon and compare it with other applied coupons
function mwd_get_applied_coupons() {
// Get the currently applied coupon's type using the $_POST global to retrieve the current coupon's code
foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
if($coupon->code == $_POST['coupon_code']) {
@rabinkumarpal
rabinkumarpal / .htaccess
Created October 12, 2022 15:14 — forked from seoagentur-hamburg/.htaccess
UPDATE 2022/10: Perfect .htaccess file for highspeed and security. You can use it for every WordPress-Website without problems. Highspeed and Security - testet on hundreds of Websites. If you are using a WordPress Multisite, change the last part of this file.
########################################################################
# OPTIMAL .htaccess FILE FOR SPEED AND SECURITY @Version 2.0.6 - 10/2022
# ----------------------------------------------------------------------
# @Author: Andreas Hecht
# @Author URI: https://seoagentur-hamburg.com
# License: GNU General Public License v2 or later
# License URI: http://www.gnu.org/licenses/gpl-2.0.html
########################################################################
@rabinkumarpal
rabinkumarpal / add-nav-parent-count.php
Created October 13, 2022 23:38 — forked from jessepearson/add-nav-parent-count.php
Functions to add a parent count to WordPress nav menus. This is useful if you need to change nav element size based on the number of parent/top level elements.
<?php
/**
* Gets the count of the parent items in a nav menu based upon the id specified.
*
* @param string $nav_id The id of the nav item to get the parent count for.
* @return bool|int False on fail, or the count of how many parent items there are.
* @uses wp_get_nav_menu_items
*/
function count_nav_parent_items( $nav_id = null ) {

Woocommerce Javascript events
Woocommerce Checkout JS events

$( document.body ).trigger( 'init_checkout' );
$( document.body ).trigger( 'payment_method_selected' );
$( document.body ).trigger( 'update_checkout' );
$( document.body ).trigger( 'updated_checkout' );
$( document.body ).trigger( 'checkout_error' );
$( document.body ).trigger( 'applied_coupon_in_checkout' );
@rabinkumarpal
rabinkumarpal / custom_plugin_WC_templates.php
Last active November 22, 2022 11:20 — forked from Dilden/custom_plugin_WC_templates.php
Useful snippet for overriding WooCommerce templates in your custom WordPress plugin. Just follow the same directory structure as if you were overriding the templates from a theme.
// Override woocommerce templates with the templates in my plugin
add_filter( 'woocommerce_locate_template', 'custom_plugin_templates');
function custom_plugin_templates ( $template, $template_name, $template_path ) {
$check_dis = str_replace('woocommerce', 'your-plugin-name-goes-here/woocommerce', $template);
if(file_exists($check_dis)) {
$template = $check_dis;
}
return $template;
};
@rabinkumarpal
rabinkumarpal / create-admin-user.php
Created January 14, 2023 19:04 — forked from wpscholar/create-admin-user.php
Create a new admin user in WordPress via code. Drop this file in the mu-plugins directory and update the variables, then load a page in WordPress to create the user. Remove the file when done.
<?php
add_action( 'init', function () {
$username = 'admin';
$password = 'password';
$email_address = '[email protected]';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
@rabinkumarpal
rabinkumarpal / functions.php
Created January 24, 2023 19:04 — forked from maddisondesigns/functions.php
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
@rabinkumarpal
rabinkumarpal / change-sender-name.php
Created January 28, 2023 08:33 — forked from sarvar/change-sender-name.php
How to Change Sender Name in Outgoing WordPress Email
// Function to change email address
function wpb_sender_email( $original_email_address ) {
return '[email protected]';
}
// Function to change sender name
function wpb_sender_name( $original_email_from ) {
return 'Tim Smith';
}