Skip to content

Instantly share code, notes, and snippets.

View railmedia's full-sized avatar

Adrian Tudorache railmedia

View GitHub Profile
@railmedia
railmedia / woo-send-email-coupon.php
Created March 16, 2021 12:23
WooCommerce send email when specific coupon is applied in the order
<?php
add_action( 'woocommerce_thankyou', 'send_email_on_coupon_usage' );
function send_email_on_coupon_usage( $order_id ) {
$order = new WC_Order( $order_id );
$coupons = $order->get_coupon_codes();
if( $coupons ) {
foreach( $coupons as $coupon ) {
if( $coupon == '<YOUR_COUPON_CODE>' ) {
<?php
function wp01234556789_remove_sidebar( $is_active_sidebar ) {
if( is_product_category() ) {
$cat_id = get_queried_object()->term_id;
$parents = get_term_parents_list($cat_id, 'product_cat', array( 'link' => false, 'inclusive' => false ));
$parents = explode( '/', $parents );
return count( $parents ) >= 3 ? true : false;
@railmedia
railmedia / gist:1b3a9c0967e0038a562e9953e4eb0893
Last active August 2, 2023 09:27
Register WordPress CPT
add_action( 'init', 'register_site_custom_posts' );
// The custom function to register a movie post type
function register_site_custom_posts() {
// Set the labels, this variable is used in the $args array
$labels = array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' ),
'add_new' => __( 'Add New Product' ),
@railmedia
railmedia / gist:ac5bb57a506dd27c9f225fd21eecb398
Created September 8, 2023 15:25
WordPress extension manifest JSON example
{
"name" : "WordPress plugin",
"slug" : "wordpress-plugin/wordpress-plugin",
"author" : "<a href='https://www.author.com'>Author</a>",
"author_profile" : "https://profiles.wordpress.org/author/",
"version" : "1.0.0.",
"download_url" : "https://www.example.com/wordpress-plugin/wordpress-plugin.zip",
"requires" : "3.0",
"tested" : "6.3.1",
"requires_php" : "8.1",
@railmedia
railmedia / order-woocommerce-products-by-slug.php
Last active October 18, 2023 10:38
Order WooCommerce products by slug
function order_woo_products_by_slug( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
// Not a query for an admin page.
// It's the main query for a front end page of your site.
if ( is_woocommerce() || is_tax( 'product_cat' ) ) {
// It's the main query for a WooCommerce category archive or for a WooCommerce page
$query->set( 'orderby', 'name' );
$query->set( 'order', 'ASC' );
}
@railmedia
railmedia / gist:e7177a2519905a485db141e65022cc93
Last active November 3, 2023 11:41
BNFW plugin detect user IP address
function bnfw_custom_get_user_ip_address() {
return $_SERVER['REMOTE_ADDR'];
}
add_shortcode( 'custom_user_ip_address', 'bnfw_custom_get_user_ip_address' );
add_filter( 'wp_mail', function( $args ) {
$args['message'] = do_shortcode( $args['message'] );
return $args;
}, 1, 1 );
@railmedia
railmedia / gforms_js_filters.js
Last active November 28, 2023 15:16
GravityForms usage of gform_datepicker_options_pre_init JS filter
/*
* Create a JS file and upload it to your child theme
* Assuming this directory structure: /wp-content/themes/<your_child_theme_folder/assets/js/gform_filters.js
*/
//PHP Side - functions.php or some other way
add_action( 'wp_enqueue_scripts', 'gform_datepicker_options_pre_init_filter' );
function gform_datepicker_options_pre_init_filter() {
//Add here any required conditionals to load below script conditionally
@railmedia
railmedia / wp-rest-basic-auth-example.php
Last active December 6, 2023 14:27
WordPress REST user Basic auth example
//Send request to http(s)://yourdomain.com/wp-json/test/v1/test
class WP_REST {
function __construct() {
add_action( 'rest_api_init', array( $this, 'routes' ) );
}
function auth_user( $request ) {
@railmedia
railmedia / jqueryui-datepicker-locale.js
Created February 10, 2024 21:34
jQueryUI datepicker locale
//Romanian
jQuery.datepicker.regional['ro'] = {
clearText: 'Sterge', clearStatus: '',
closeText: 'Inchide', closeStatus: 'Inchide fara modificari',
prevText: '<Inapoi', prevStatus: 'Vezi luna precedenta',
nextText: 'Inainte>', nextStatus: 'Vezi luna viitoare',
currentText: 'Curenta', currentStatus: 'Vezi luna curenta',
monthNames: ['Ianuarie','Februarie','Martie','Aprilie','Mai','Iunie','Iulie','August','Septembrie','Octombrie','Noiembrie','Decembrie'],
monthNamesShort: ['Ian','Feb','Mar','Apr','Mai','Iun','Iul','Aug','Sep','Oct','Nov','Dec'],
add_action('woocommerce_product_options_advanced', function() {
woocommerce_wp_text_input([
'id' => '_price_suffix',
'label' => __( 'Price suffix', 'woocommerce' ),
]);
});
add_action('woocommerce_process_product_meta', function($post_id) {
$product = wc_get_product($post_id);
$price_suffix = isset($_POST['_price_suffix']) ? $_POST['_price_suffix'] : '';