Skip to content

Instantly share code, notes, and snippets.

View Njengah's full-sized avatar
👨‍💻
Coding & Learning Everyday

Joe Njenga Njengah

👨‍💻
Coding & Learning Everyday
View GitHub Profile
@Njengah
Njengah / custom-add-to-cart-text.php
Created February 26, 2024 23:40
Change Add to Cart Text WooCommerce
<?php
// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'storemizer_single_add_to_cart_text' );
function storemizer_single_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
}
// To change add to cart text on product archives(Collection) page
add_filter( 'woocommerce_product_add_to_cart_text', 'storemizer_product_add_to_cart_text' );
function storemizer_product_add_to_cart_text() {
@Njengah
Njengah / fiddle_493421.php
Created October 9, 2019 14:51 — forked from phpfiddle/fiddle_493421.php
Php color palette shade generator
<?php
class ColorPalette{
public $color;
public function __construct($color){
$this->color = $color;
}
public function color_mod($hex, $diff) {
$rgb = str_split(trim($hex, '# '), 2);
@Njengah
Njengah / create_wordpress_login_form_shortcode.php
Created February 25, 2020 17:39
Create Custom WordPress login form without plugin [ WordPress Login form Shortcode ]
<?php
/**
* Code to Create Custom WordPress login form without plugin
* @author Joe Njenga
* @ gist -
*/
// Step 1: Create shortcode
function njengah_add_login_shortcode() {
@Njengah
Njengah / add-submenu-page_to_custom_post_type_example.php
Created January 22, 2020 17:06
Simple function to add submenu page to a custom post type menu in WordPress admin
<?php
// Hook
add_action('admin_menu', 'add_tutorial_cpt_submenu_example');
//Callback function
function add_tutorial_cpt_submenu_example(){
<?php
/* Redirect user after check out */
add_action( 'template_redirect', 'njengah_custom_redirect_after_purchase' );
function njengah_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
@Njengah
Njengah / numeric-pagination-wordpress.php
Created August 21, 2020 23:51
Create numeric pagination in WordPress - Snippet to create numeric pagination in WordPress for this tutorial - https://njengah.com/wordpress-custom-pagination/
<?php
/**
* Create numeric pagination in WordPress
*/
// Get total number of pages
global $wp_query;
$total = $wp_query->max_num_pages;
// Only paginate if we have more than one page
<?php
/**
* Skip Cart and Redirect to Checkout
* Add to functions.php of child theme
*/
add_filter('woocommerce_add_to_cart_redirect', 'njengah_skip_cart_redirect_to_checkout_page');
function njengah_skip_cart_redirect_to_checkout_page() {
<?php
/**
* Add Remove button to WooCommerce checkout page - cart items
*/
add_filter('woocommerce_cart_item_name', 'njengah_filter_wc_cart_item_remove_link', 10, 3);
function njengah_filter_wc_cart_item_remove_link($product_name, $cart_item, $cart_item_key)
{
@Njengah
Njengah / add_active_menu_class_jquery.js
Created March 15, 2020 05:00
Add active menu class based on URL using jQuery more explanation here - https://njengah.com/add-active-navigation-class-based-on-url/
/**
* Add active menu class based on URL using jQuery
*/
jQuery(function($) {
var path = window.location.href;
$('ul a').each(function() {