Skip to content

Instantly share code, notes, and snippets.

View Asikur22's full-sized avatar
๐Ÿ’œ
Web Developer | In Love with WordPress

Asiqur Rahman Asikur22

๐Ÿ’œ
Web Developer | In Love with WordPress
View GitHub Profile
@Asikur22
Asikur22 / hooks.php
Created October 27, 2022 23:40
Woocommerce shop product per page dropdown #ProductPerPage
/*
* Woocommerce shop product per page dropdown
*/
add_action( 'woocommerce_before_shop_loop', 'gl_asiq_woo_per_page_dropdown', 31 );
function gl_asiq_woo_per_page_dropdown() {
$per_page = filter_input( INPUT_GET, 'per_page', FILTER_SANITIZE_NUMBER_INT );
$orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_STRING );
$per_page_options = array(
'12' => '12',
'24' => '24',
@Asikur22
Asikur22 / style.scss
Created October 27, 2022 18:40
Woocommerce Plus Minus Quantity Buttons
.quantity {
display: flex;
border: 1px solid rgba(11, 11, 11, 0.1);
width: 90px;
.qty {
padding: 10px;
border: 0;
background-color: transparent;
-moz-appearance: textfield;
@Asikur22
Asikur22 / hooks.php
Created October 27, 2022 10:18
Add Meta Box to Woocommerce Product #WooMeta
/*
* Product Meta Fields
*/
add_action( 'woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields' );
function woocommerce_product_custom_fields() {
global $product_object;
echo '<div class="product_custom_field">';
// Custom Product Text Field
@Asikur22
Asikur22 / php_array.md
Last active September 12, 2022 07:35
PHP Array Functions

array_walk

  • Only for echo
  • create new array

array_map

  • For echo/return
  • create new array
  • return modified value

array_filter

@Asikur22
Asikur22 / readme.md
Created August 26, 2022 16:35
www or non-www

Without www, browsers have to store different cookie for every subdomain request. As you can imagine, the process is highly inefficient and slows down loading times on the website as a result.

It is better to use www in URLs

@Asikur22
Asikur22 / wp-woocommerce-allow-non-variation-attributes-frontend-selection.php Woocommerce: use non-variation attributes from frontend - allow customers to select term (option) from non-variation attributes on variable or simple products frontend pages, add selection to cart item, display it in cart, add it to order item
<?php
/**
* Inspired from: https://gist.github.com/dazecoop/548b2621e86fb030da8e5adb1bfe484f
*
* How to use:
* - add to your function.php or related
*
* What you can use it for:
* Variable products:
* - you have variable product with some attributes not used for variations
@Asikur22
Asikur22 / scripts.js
Created April 9, 2022 14:39
Shopify add and remove item from the cart
let cartBtn = document.querySelector("YOUR CART BUTTON CLASS NAME")
const form = document.getElementById("YOUR FORM ID")
form.addEventListener("submit", (e) => {
e.preventDefault()
if (cartBtn.getAttribute("data-variant-id")) {
removeItem()
}
else {
addItem()
}
@Asikur22
Asikur22 / cmd.md
Last active April 6, 2022 04:12
Laravel Create Controller with terminal
php artisan make:model Todo -mcrf
  • -m, --migration Create a new migration file for the model.
  • -c, --controller Create a new controller for the model.
  • -r, --resource Indicates if the generated controller should be a resource controller
  • -f, --factory Create a new Factory file for this model.
@Asikur22
Asikur22 / helper-functions.php
Created March 26, 2022 06:48
Randomly Change Background Color in WordPress
function wpb_bg() {
$rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
$color = '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)]. $rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
echo $color;
}
// Use
<body <?php body_class(); ?> style="background-color:<?php wpb_bg();?>">>
@Asikur22
Asikur22 / style.css
Created March 23, 2022 11:36
br tag fix on mobile
@media (max-width: 1199px) {
.br-fix p br,
.br-fix br {
content: "";
&:after {
content: " ";
}
}
}