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() {
<?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() {
@Njengah
Njengah / remove-wordpress-plugin-update-notifications.php
Created March 13, 2020 22:42
Remove WordPress plugin notification for a specific plugin
<?php
/**
* Remove Plugin Update Notifications for Specific Plugin : example-plugin-folder/example-plugin-base-file.php
*/
function njengah_remove_plugin_update_notifications($value) {
if ( isset( $value ) && is_object( $value ) ) {
unset( $value->response[ 'example-plugin-folder/example-plugin-base-file.php' ] );
@Njengah
Njengah / woocommerce_create_order_comments_field.php
Created March 12, 2020 20:37
Code snippet to create order comments field.
<?php
//Create order comments field
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$fields = WC()->checkout->checkout_fields['billing'];
} else {
$fields = WC()->checkout->get_checkout_fields( 'billing' );
}
<?php
/**
* Code Snippet should be added to the functions.php to make WooCommerce order comments required
*/
add_action('woocommerce_after_checkout_validation', 'njengah_make_woocommerce_order_comments_required');
function njengah_make_woocommerce_order_comments_required() {