Skip to content

Instantly share code, notes, and snippets.

View smeric's full-sized avatar

Sébastien Méric smeric

View GitHub Profile
@smeric
smeric / woo_cart_has_virtual_product.php
Last active September 16, 2023 03:02 — forked from Katamo/gist:10243188
Check if the WooCommerce cart contains virtual product
<?php
/**
* Check if the cart contains virtual product
*
* @return bool
*/
function woo_cart_has_virtual_product(){
global $woocommerce;
// By default, no virtual product
@smeric
smeric / extend-woocommerce-memberships-period.php
Created October 6, 2016 12:47
WooCommerce Memberships : allow renewal for active memberships even before membership expiration.
<?php
/**
* Allow membership renewal for active memberships
*/
add_filter( 'wc_memberships_valid_membership_statuses_for_renewal', 'my_valid_membership_statuses_for_renewal' );
function my_valid_membership_statuses_for_renewal( $statuses = array() ) {
$statuses[] = 'active';
return $statuses;
}
@smeric
smeric / add_editor_styles_by_post_id.php
Last active August 10, 2021 13:04
This is how to assign a specific stylesheet to a specific post type post id on WordPress Gutenberg edit screen. See https://sebastien-meric.com/appliquer-gutenberg-feuille-de-style-post-id/ (in french).
<?php
/**
* Registers a specific editor stylesheet for a specific post id.
*/
function actusoins_add_editor_styles_by_post_id() {
global $pagenow;
// Are we on a post edit page ?
if ( isset( $pagenow ) && 'post.php' === $pagenow ) {
$post_id = $_GET['post'];
@smeric
smeric / woocommerce_local_pickup_time_plugin_custom_2.php
Last active July 8, 2021 08:18
This removes the title entirely to get rid of a duplicate sentence, resolving at the same time a <h2> problem... And offers a way to make the checkout choice of the date optionnal !
<?php
/**
* Remove the WooCommerce Local Pickup Time plugin checkout page select field title.
* And offers a way to make the checkout choice of the date optionnal !
*
* @see https://github.com/WC-Local-Pickup/woocommerce-local-pickup-time/issues/103
* @see https://github.com/WC-Local-Pickup/woocommerce-local-pickup-time/issues/104
*/
if ( class_exists( 'Local_Pickup_Time' ) ) {
// Add a checkbox field to make the pickup date choice optionnal
<?php
// @link https://github.com/woocommerce/woocommerce/blob/master/includes/admin/wc-meta-box-functions.php#L141
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
@smeric
smeric / yoast-seo-breadcrumbs-for-woocommerce.php
Last active June 21, 2021 22:13
Add WooCommerce endpoints to Yoast SEO breadcrumbs
<?php
/**
* Add WooCommerce endpoints to Yoast SEO breadcrumbs
*
* @link https://gist.github.com/smeric/b544f154ea752e47d0427f3e1ae901b5
* @version 1.0.1
* @package yoast_seo_breadcrumbs_for_woocommerce_endpoints
*
* @wordpress-plugin
* Plugin Name: Yoast SEO breadcrumbs addon
@smeric
smeric / woocommerce_local_pickup_time_plugin_custom.php
Created November 10, 2020 22:20
This removes the title entirely to get rid of a duplicate sentence, resolving at the same time a <h2> problem...
<?php
/**
* Remove the WooCommerce Local Pickup Time plugin checkout page select field title.
*
* @see https://github.com/WC-Local-Pickup/woocommerce-local-pickup-time/issues/103
* @see https://github.com/WC-Local-Pickup/woocommerce-local-pickup-time/issues/104
*/
if ( class_exists( 'Local_Pickup_Time' ) ) {
// Remove the default local pickup time field from the checkout page.
remove_action( apply_filters( 'local_pickup_time_select_location', 'woocommerce_after_order_notes' ), array( Local_Pickup_Time::get_instance(), 'time_select') );
@smeric
smeric / DB.php
Last active September 20, 2020 21:59
Mysqli Class
<?php
namespace SMeric\Utilities;
/**
* Simple MySQLi Class 0.3.2
*
* @author JReam
* @license GNU General Public License 3 (http://www.gnu.org/licenses/)
*
* This program is free software; you can redistribute it and/or modify it
@smeric
smeric / remove-old-slugs-redirects.php
Last active May 27, 2020 03:45
WordPress plugin. Removes selected old slugs/permalinks from database.
<?php
/**
* Remove old slugs redirects.
*
* Removes selected old slugs/permalinks from database.
*
* @package WordPress_Remove_Old_Slugs_Redirects
* @author Sébastien Méric <sebastien.meric@gmail.com>
* @credit Algoritmika Ltd. <http://www.algoritmika.com>
* @license GPL-2.0+
@smeric
smeric / gform-generate-username.php
Created February 12, 2016 16:34
Username auto generation for Gravity Form User Registration Add-on
<?php
/**
* Username auto generation for Gravity Form User Registration Add-on
*
* see https://www.gravityhelp.com/documentation/article/gform_username/
*/
add_filter( 'gform_username', 'auto_username', 10, 4 );
function auto_username( $username, $feed, $form, $entry ) {
//$username = strtolower( rgar( $entry, '2.3' ) . rgar( $entry, '2.6' ) );