Skip to content

Instantly share code, notes, and snippets.

View dr5hn's full-sized avatar
🪄
Turning ☕ into code | Full Stack Magician 🧙‍♂️✨

Darshan Gada dr5hn

🪄
Turning ☕ into code | Full Stack Magician 🧙‍♂️✨
View GitHub Profile
@dr5hn
dr5hn / randomColor.php
Last active September 24, 2017 13:52
Generating a Random HEX Color Code with PHP For Example : #ffffff
<?php
function randomColor() {
//Start Color with #
$str = '#';
//Total Number of Iteration Required for HEX Color is 6
for ($i = 0; $i < 6; $i++) {
//Genrate Random Number Between 0 to 15
$randNum = rand(0, 15);
//Replace 10 - 15 to A - F
switch ($randNum) {
@dr5hn
dr5hn / functions.php
Last active September 24, 2017 14:13
Registering Menu, Custom Post Types, Custom Fields & Custom Plugins to REST API in Wordpress
<?php
//Registering Menu Items to REST API (API URL : http://website.com/wp-json/menu/)
function get_menu() {
# Change 'hamburger' to your own navigation slug.
return wp_get_nav_menu_items('hamburger');
}
add_action( 'rest_api_init', function () {
register_rest_route( 'spirit', '/menu', array(
@dr5hn
dr5hn / functions.php
Created October 15, 2017 08:06
How to add Custom Settings to Wordpress Appearance Customize Section
<?php
/**
* Custom Wordpress Customize Settings -- By Darshan Gada
* @param webgeeks (Replace webgeeks with your theme name)
* @function webgeeks_theme_options
*/
function webgeeks_theme_options( $wp_customize ) {
//Sections, settings and controls will be added here
@dr5hn
dr5hn / functions.php
Created October 15, 2017 08:07
Removing WooCommerce Shop Section Breadcrumbs
<?php
//Removing the Breadcrumbs -- By Darshan Gada
add_action('init','fila_remove_wc_breadcrumbs');
function fila_remove_wc_breadcrumbs() {
remove_action('woocommerce_before_main_content','woocommerce_breadcrumb',20,0);
}
?>
@dr5hn
dr5hn / functions.php
Created October 15, 2017 08:11
WooCommerce - How to Change Add to Cart Button Text in Wordpress
<?php
//WooCommerce. How to change “Add to cart” button text -- By Darshan Gada
add_filter( 'add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); // < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 +
function woo_custom_cart_button_text() {
return __( 'ADD TO BASKET', 'woocommerce' );
}
?>
@dr5hn
dr5hn / variables_variable.php
Created October 15, 2017 08:17
How to create dynamic Variable Name or Create variable from variable in PHP
<?php
$a = 'Hello';
$$a = 'World!'; // This interprets $hello = 'world';
echo "$a ${$a}"; //This will Print Hello World {PHP 7.0}
echo "$a $hello"; // This will also produce the same output Hello World
?>
@dr5hn
dr5hn / functions.php
Created October 15, 2017 08:19
Change Continue Shopping Link in within WooCommerce
<?php
/**
* Return the permalink of the shop page for the continue shopping redirect filter -- By Darshan Gada
*
* @param string $return_to
* @return string
*/
function my_woocommerce_continue_shopping_redirect( $return_to ) {
return get_permalink( wc_get_page_id( 'shop' ) );
}
@dr5hn
dr5hn / functions.php
Created October 15, 2017 08:43
How to change Number of Upsell products displayed on Single Product Page in Woocommerce
<?php
//Changing Number of Upsell products display on Single Product page -- By Darshan Gada
add_filter( 'woocommerce_output_related_products_args', 'wc_change_number_related_products' );
function wc_change_number_related_products( $args ) {
$args['posts_per_page'] = 1;
$args['columns'] = 4; //change number of upsells here
return $args;
}
@dr5hn
dr5hn / functions.php
Created October 15, 2017 08:47
How to Update Add to Cart and Select Options Button Text on Shop Archive Page in Woocommerce
<?php
// Updating Select Options and Add to Cart Button Text on Shop Archive Page -- By Darshan Gada
add_filter( 'woocommerce_product_add_to_cart_text' , 'woo_custom_view_button_text' );
function woo_custom_view_button_text() {
global $product;
$product_type = $product->get_type();
switch ($product_type) {
case 'variable':
return __( 'VIEW PRODUCT', 'woocommerce' ); //this will change "Select Options" to "View Product"
@dr5hn
dr5hn / functions.php
Created October 15, 2017 08:53
How to change number of products displayed on Shop Archive Page Woocommerce
<?php
//Change Number of Products Display on Shop Archive Page -- By Darshan Gada
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 100;
return $cols;
}