Skip to content

Instantly share code, notes, and snippets.

@wpflames
wpflames / functions.php
Created February 15, 2022 17:23
Check if specific category is in the cart
<?php
// =========================================================================
// CHECK IF SPECIFIC CATEGORY IS IN THE CART
// =========================================================================
function check_specific_category_in_cart() {
// Set $cat_in_cart to false
$cat_in_cart = false;
// Loop through all products in the Cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
@wpflames
wpflames / delivery-dates.js
Created February 15, 2022 16:52
Disable Weekends and Previous Dates in DatePicker
jQuery(document).ready(function () {
jQuery(".checkout-date-picker").datepicker({
// Disable Weekends
beforeShowDay: jQuery.datepicker.noWeekends,
// Disable Previous Dates
minDate: 0
});
});
@wpflames
wpflames / functions.php
Last active February 14, 2022 19:50
Change Continue Shopping link to the Previously Visited Page in WooCommerce
<?php
// =========================================================================
// Changes the redirect URL for the Return To Shop button in the cart.
// =========================================================================
function wc_empty_cart_redirect_url() {
if( WC()->cart->is_empty() ) {
return wc_get_page_permalink( 'shop' );
} else{
return $_SERVER['HTTP_REFERER'];
@wpflames
wpflames / functions.php
Last active February 11, 2022 15:21
Shorten the post title in WordPress
<?php // Don't copy the opening tag
// =========================================================================
// SHORTEN THE TITLE
// =========================================================================
function shortenTitle(){
$thetitle = get_the_title();
$getlength = strlen($thetitle);
$thelength = 45;
echo substr($thetitle, 0, $thelength);
@wpflames
wpflames / functions.php
Last active February 9, 2022 20:10
How to display Categories and Products in Separate Lists in Woo
<?php // Don't copy the opening php tag
// =========================================================================
// SEPARATE PRODUCTS AND SUBCATEGORY ON ARCHIVE PAGES
// =========================================================================
function display_product_subcategories( $args = array() ) {
$parentid = get_queried_object_id();
$args = array(
'parent' => $parentid
@wpflames
wpflames / package.json
Created February 7, 2022 15:43
Package.json for Webpack
{
"name": "version-4",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
@wpflames
wpflames / webpack.config.js
Created February 7, 2022 15:40
Webpack with SASS Loader
const path = require('path');
module.exports = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
entry: [
__dirname + '/assets/js/app.js',
__dirname + '/assets/sass/style.scss'
],
output: {
@wpflames
wpflames / webpack.config.js
Created February 7, 2022 09:45
Webpack basic config
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js'
},
mode: "development"
}
@wpflames
wpflames / functions.php
Created February 4, 2022 14:05
Display WooCommerce Product Category Subtitle
// =========================================================================
// DISPLAY PRODUCT CATEGORY SUBTITLE
// =========================================================================
function add_product_cat_subtitle(){
$term_id = get_queried_object()->term_id;
$post_id = 'product_cat_'.$term_id;
$subtitle = get_field('alcim', $post_id); //
echo $subtitle;
@wpflames
wpflames / functions.php
Created February 4, 2022 08:15
How to add Google Maps API Key to WordPress
function addGoogleMapsKey($api) {
$api['key'] = 'your_api_key';
return $api;
}
add_filter('acf/fields/google_map/api', 'addGoogleMapsKey');