Skip to content

Instantly share code, notes, and snippets.

@wpflames
wpflames / style.scss
Created April 11, 2022 10:16
Accordion styling
// Accordion
// ************************
.accordion-item{
.accordion-title{
border-bottom: 1px solid;
padding: 15px 15px 10px;
background: rgba(218,217,234,1);
cursor: pointer;
transition: all 0.3s ease-in-out;
&:hover{
@wpflames
wpflames / functions.php
Last active April 8, 2022 13:15
Hide Free Shipping Notice of Current User is WholeSale Customer
<?php
// =========================================================================
// Hide Free Shipping Notice of Current User is WholeSale Customer
// =========================================================================
function free_shipping_cart_notification() {
$wholesaler = false;
// Get current user role
global $current_user;
@wpflames
wpflames / divider.html
Last active April 2, 2022 00:15
Shadow divider
<div class="h-divider">
<div class="shadow"></div>
</div>
<style>
.h-divider {
margin: 80px auto 40px;
width: 80%;
position: relative;
}
@wpflames
wpflames / functions.php
Created March 26, 2022 08:56
Add Custom Fields to Rest API
<?php
// =============================================================
// Add Custom Fields to Rest API
// =============================================================
function add_rest_api_custom_fields() {
register_rest_field('post', 'authorName', array(
'get_callback' => function() {return get_the_author();}
));
register_rest_field('post', 'yourCustomField', array(
'get_callback' => function() {return get_field('custom-field-name');}
@wpflames
wpflames / acf-query.php
Last active March 23, 2022 19:02
Query WordPress Posts by Advanced Custom Fields
<?php
// args
$args = array(
'numberposts' => -1,
'post_type' => 'YOUR_POST_TYPE',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'YOUR_ACF_SLUG',
@wpflames
wpflames / functions.php
Created March 22, 2022 11:54
Unset Specific Shipping Methods if Free Shipping is Available
<?php
// =========================================================================
// Unset Specific Shipping Method if Free Shipping is Available
// =========================================================================
function unset_shipping_when_free_is_available_in_zone( $rates, $package ) {
// Only unset rates if free_shipping is available
if ( isset( $rates['free_shipping:8'] ) ) {
unset( $rates['flat_rate:1'] );
}
return $rates;
@wpflames
wpflames / functions.php
Created March 22, 2022 11:52
Unset All Shipping Methods if Free Shipping is Available
// =========================================================================
// Unset Shipping Methods if Free Shipping is Available
// =========================================================================
function unset_shipping_when_free_is_available_all_zones( $rates, $package ) {
$all_free_rates = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$all_free_rates[ $rate_id ] = $rate;
break;
}
@wpflames
wpflames / functions.php
Created March 22, 2022 11:15
Add fee to checkout for COD shipping except specific shipping zone
<?php
// =========================================================================
// WooCommerce add fee to checkout for a gateway ID
// =========================================================================
function add_checkout_fee_for_gateway() {
// Check if specific shipping zone in the cart
$shipping_class_target = 32; // shipping class ID
$in_cart = false;
@wpflames
wpflames / breadcrumbs.php
Created March 16, 2022 16:44
Display Breadcrumbs without Plugin in WordPress
<?php
$theParent = wp_get_post_parent_id(get_the_ID());
if ($theParent) { ?>
<div class="wrap">
<div class="breadcrumbs">
<p>
<a href="<?php echo site_url(); ?>">
<svg id="icon-home" width="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
<path d="M511.8 287.6L512.5 447.7C512.5 450.5 512.3 453.1 512 455.8V472C512 494.1 494.1 512 472 512H456C454.9 512 453.8 511.1 452.7 511.9C451.3 511.1 449.9 512 448.5 512H392C369.9 512 352 494.1 352 472V384C352 366.3 337.7 352 320 352H256C238.3 352 224 366.3 224 384V472C224 494.1 206.1 512 184 512H128.1C126.6 512 125.1 511.9 123.6 511.8C122.4 511.9 121.2 512 120 512H104C81.91 512 64 494.1 64 472V360C64 359.1 64.03 358.1 64.09 357.2V287.6H32.05C14.02 287.6 0 273.5 0 255.5C0 246.5 3.004 238.5 10.01 231.5L266.4 8.016C273.4 1.002 281.4 0 288.4 0C295.4 0 303.4 2.004 309.5 7.014L416 100.7V64C416 46.33 430.3 32 448 32H480C497.7 32 512 46.33 512 64V185L564.8 231.5C572.8 238.5 576.9 246.5
@wpflames
wpflames / functions.php
Created March 16, 2022 12:42
Add custom class to WordPress excerpt
<?php
// =========================================================================
// ADD CLASS TO EXCERPT
// =========================================================================
function add_class_to_excerpt ($post_excerpt) {
$post_excerpt = '<p class="whatever">' . $post_excerpt . '</p>';
return $post_excerpt;
}
add_filter ('get_the_excerpt','add_class_to_excerpt');