Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

NS nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / export-active-woo-subscripitions.sql
Last active September 15, 2023 12:11
Export all ACTIVE subscriptions from WooCommerce Subscriptions using a MySQL query
SELECT
p.ID as 'Subscription ID',
p.post_status as 'Subscription Status',
pm1.meta_value as 'Billing First Name',
pm2.meta_value as 'Billing Last Name',
pm3.meta_value as 'Billing Email',
oitems.order_item_name as 'Product',
pm4.meta_value as 'Order Total',
pm5.meta_value as 'Order Tax'
FROM wp_posts p
@nfsarmento
nfsarmento / functions.php
Created July 4, 2023 19:46
Shortcode to show post title truncated
<?php
/**
*
* Shortcode to show post title truncated
*
* [posttitle]
*
*/
function ns_post_title_shortcode(){
return wp_trim_words( get_the_title(), 10 );
@nfsarmento
nfsarmento / functions.php
Created July 4, 2023 19:45
Shortcode to show parent category
<php
/**
*
* Shortcode to show parent category
*
* [postcat]
*
*/
function ns_post_cat_shortcode(){
@nfsarmento
nfsarmento / functions.php
Created July 4, 2023 19:44
Post estimated reading time shortcode
<?php
/**
*
* Post estimated reading time shortcode
*
*/
function ns_reading_time_shortcode() {
$content = get_post_field( 'post_content', $post->ID );
@nfsarmento
nfsarmento / functions.php
Created March 29, 2023 14:36
Add new WooCommerce account menu item for a specific members role
<?php
/*
*
* Add new WooCommerce account menu item for a specific members role
*
* */
add_filter ( 'woocommerce_account_menu_items', 'ns_members_link', 40 );
function ns_members_link( $menu_links ){
$product_ids = array( 38, 41, 85, 95 );
@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 / ns-create-vh-db-wp-ssl.sh
Last active February 23, 2023 00:10
bash script to create mariadb database, create nginx virtual host, setup WordPress and install SSL.
#!/bin/bash
# -------------------------------------------------
# Make site directory
# Download WP and install WP to site directory
# Set WP configuration
# Configure NGINX for new domain-name
# -------------------------------------------------
#
# Requirments:
#
@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',