Skip to content

Instantly share code, notes, and snippets.

View younes-dro's full-sized avatar
🏡
Working from home

WordPress | React | Gutenberg Developer younes-dro

🏡
Working from home
View GitHub Profile
@younes-dro
younes-dro / sass-extend-and-loop-for
Created September 3, 2019 22:59
combine @extend and a loop for with Sass
%white-div{
color:#fff;
}
@for $j from 1 to 6{
div-#{$j}{
@extend %white-div;
}
}
@younes-dro
younes-dro / wp add age slug in body css class
Created September 3, 2019 23:02
Add page slug in body css class
/**
* Add page slug in body class
*
* @global type $post
* @param string $classes
* @return string
*/
//Page Slug Body Class
function add_slug_body_class( $classes ) {
@younes-dro
younes-dro / custom widget glyph icon
Created September 6, 2019 00:41
generate custom widget glyph icon using Sass : loop , mixin , map
@mixin sidebar-title-icon($content){
.widget-title{
&::before{
font-family: "Ionicons";
content: $content;
display: inline-block;
margin: 0 10px 0 0;
}
}
}
@younes-dro
younes-dro / gist:97bb6a0a4f8f8f225e129f6b8448870b
Last active October 9, 2019 15:41
Display vairation products as a table
add_action('plugins_loaded', function(){
function woocommerce_variable_add_to_cart() {
global $product, $post;
// print_r($product->product_type);
$variations = $product->get_available_variations();
// ob_start(); // Start buffering
?>
<form class="cart" action="<?php echo esc_url($product->add_to_cart_url()); ?>" method="post" enctype="multipart/form-data">
<table class="dro-variable-product" id="dro-variable-product">
<tbody>
add_action('pre_get_posts', 'cgy_same_day');
function cgy_same_day($query) {
if ($query->is_home() && $query->is_main_query()) {
$today = getdate();
$query->set('date_query', array(
array(
'day' => $today['mday'],
@younes-dro
younes-dro / regex-3-lettre-3-number
Created January 9, 2020 05:37
Verify a pattern : 6 char lenght ( 3 string and 3 number)
if(isset($_POST['log']) && !empty($_POST['log']) && $_POST['log']==1){
$login = trim($_POST['login']);
$pw = trim($_POST['pw']);
if(strlen($login) == 6 && strlen($pw) == 6){
$n_log=0;
@younes-dro
younes-dro / remove action from global $wp_filter
Created January 10, 2020 04:06
2 In cases like this the Wordpress adds a hash (unique id) to the function name and stores it in the global $wp_filter variable. So if you use remove_filter function nothing will happen
function my_remove_filter($tag, $function_name, $priority = 10){
global $wp_filter;
if( isset($wp_filter[$tag]->callbacks[$priority]) and !empty($wp_filter[$tag]->callbacks[$priority]) ){
$wp_filter[$tag]->callbacks[$priority] = array_filter($wp_filter[$tag]->callbacks[$priority], function($v, $k) use ($function_name){
return ( stripos($k, $function_name) === false );
@younes-dro
younes-dro / wp walker manu
Created January 15, 2020 01:37
Customize the wordpres menu with nav walker
// functions.php
class themeslug_walker_nav_menu extends Walker_Nav_Menu {
// add classes to ul sub-menus
function start_lvl(&$output, $depth) {
// depth dependent classes
$indent = ( $depth > 0 ? str_repeat("\t", $depth) : '' ); // code indent
$display_depth = ( $depth + 1); // because it counts the first submenu as 0
$classes = array(
'sub-menu',
@younes-dro
younes-dro / sale-badge-woocommerce
Created January 17, 2020 04:25
Change the default Sale badge woocommerce
add_filter( 'woocommerce_sale_flash', 'wc_custom_replace_sale_text' );
function wc_custom_replace_sale_text( $html ) {
return str_replace( __( 'Sale!', 'woocommerce' ), __( 'My sale text!', 'woocommerce' ), $html );
}
@younes-dro
younes-dro / archive-product
Created January 18, 2020 16:52
Custom archive CPT
<?php
/**
* The template for displaying archive pages
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/