Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

NS nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / functions.php
Created March 29, 2023 14:34
Add new role for specific product when order is completed WooCommerce
<?php
/*
*
* Add new role for specific product when order is completed WooCommerce
*
* */
add_action( 'woocommerce_order_status_completed', 'ns_change_role_on_purchase' );
function ns_change_role_on_purchase( $order_id ) {
// get order object and items
@nfsarmento
nfsarmento / functions.php
Created March 29, 2023 14:33
Force registering when buying specific products on WooCommerce
<?php
/*
*
* Force registering when buying specific products on WooCommerce
*
* */
add_action( 'woocommerce_after_checkout_validation' , 'ns_restict_registration_for_some_products', 10, 2 );
function ns_restict_registration_for_some_products( $data, $errors ) {
if( isset( $data['createaccount'] ) && !$data['createaccount'] ) {
@nfsarmento
nfsarmento / functions.php
Last active March 13, 2023 19:45 — forked from dibakarjana/functions.php
Wordpress: Send Email after any Post type status change
/**
*
* https://codex.wordpress.org/Post_Status_Transitions
*
* Send email to admin after user create new product from frontend form.
* Send emails on products publication
* @param WP_Post $post
*
*
*/
@nfsarmento
nfsarmento / posts-metakey.php
Created February 16, 2023 16:37
Show posts with and without meta_key and order them the ones with meta_key on the top
<?php
$args = array(
'post_type' => 'projects',
'posts_per_page' => 9,
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'featured-checkbox',
@nfsarmento
nfsarmento / addinfunctions.php
Created January 30, 2023 20:34 — forked from neilgee/addinfunctions.php
Gravity Form Word Count
<?php
/* Gravity Forms Word Count Script */
function els_load_scripts() {
wp_enqueue_script('gravity-forms-word-count', get_stylesheet_directory_uri() . '/js/jquery.gravity_word_count.js', array('jquery'), '0.1', true);
}
add_action('wp_enqueue_scripts', 'els_load_scripts');
/*Then in the form, for fields that need the word count, add the class ‘els-word-count[300].' Change [300] as needed for the maximum words that can be added to that particular field.*/
/*Source http://www.gravityhelp.com/forums/topic/maximum-word-count#post-149331*/
@nfsarmento
nfsarmento / NPM installation requirements
Created June 6, 2022 11:21 — forked from kompuser/NPM installation requirements
Roots Sage Gulpfile Including Critical CSS and CombineMQ
npm install --save asset-builder browser-sync del gulp gulp-autoprefixer gulp-changed gulp-concat gulp-cssnano gulp-flatten gulp-if gulp-imagemin gulp-jshint gulp-less gulp-plumber gulp-rename gulp-rev gulp-sass gulp-sourcemaps gulp-uglify imagemin-pngcrush jshint jshint-stylish lazypipe merge-stream minimist run-sequence traverse wiredep gulp-util gulp-combine-mq critical gulp-rename gulp-penthouse
@nfsarmento
nfsarmento / 01-gulpfile.js
Created June 3, 2022 19:32 — forked from markgoodyear/01-gulpfile.js
Comparison between gulp and Grunt. See http://markgoodyear.com/2014/01/getting-started-with-gulp/ for a write-up.
/*!
* gulp
* $ npm install gulp-ruby-sass gulp-autoprefixer gulp-cssnano gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev
*/
// Load plugins
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
@nfsarmento
nfsarmento / functions.php
Created May 17, 2022 21:56
Disable admin notices In WordPress for all users apart from the the ID define on the Array
<?php
/**
* How To Disable Admin Notices In WordPress
*
*/
add_action('admin_enqueue_scripts', 'os_admin_theme_style');
add_action('login_enqueue_scripts', 'os_admin_theme_style');
function os_admin_theme_style() {
$super_admins = array( 5 );
if( ! in_array( get_current_user_id(), $super_admins ) ){
@nfsarmento
nfsarmento / functions.php
Created October 1, 2021 10:06
Custom contact form shortcode - used for custom product enquiry on WooCommerce
/**
*
* Shortcode contact form
*/
// @codingStandardsIgnoreStart
function decorativefair_shortcode_product_form($item) {
ob_start();
global $post, $product;
$author_name = get_the_author_meta( 'user_email', $product->post->post_author );
@nfsarmento
nfsarmento / functions.php
Created September 13, 2021 10:49
WordPress Countdown Timer Shortcode
<?php
/*
*
* Countdown Timer Shortcode
* [cdt month="9" day="28" year="2021"] This is content that will only be shown after a set number of days.[/cdt]
*
*/
// @codingStandardsIgnoreStart
function aet_content_countdown($atts, $content = null){
extract(shortcode_atts(array(