Skip to content

Instantly share code, notes, and snippets.

Avatar

Sébastien Méric smeric

View GitHub Profile
View checkbox_input.php
<?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 / woo_cart_has_virtual_product.php
Last active Jan 24, 2021 — forked from Katamo/gist:10243188
Check if the WooCommerce cart contains virtual product
View woo_cart_has_virtual_product.php
<?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 / woocommerce_local_pickup_time_plugin_custom_2.php
Last active Jul 8, 2021
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 !
View woocommerce_local_pickup_time_plugin_custom_2.php
<?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
@smeric
smeric / woocommerce_local_pickup_time_plugin_custom.php
Created Nov 10, 2020
This removes the title entirely to get rid of a duplicate sentence, resolving at the same time a <h2> problem...
View woocommerce_local_pickup_time_plugin_custom.php
<?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 Sep 20, 2020 — forked from alixcan/mysql li jream
Mysqli Class
View DB.php
<?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 / editor-container-query.php
Last active Apr 22, 2020
Use this javascript code to add classes to the .block-editor__typewriter block just following the .editor-styles-wrapper block. Those classes are here to mimick front-end breakpoints because of ineffectiveness of media queries. See https://sebastien-meric.com/gutenberg-responsive-container-queries/ (in french).
View editor-container-query.php
<?php
/**
* Enqueue in editor pages a specific editor-script.js file
*/
function my_theme_editor_container_query() {
// Load the editor script within Gutenberg.
wp_enqueue_script( 'my_theme_editor_container_query', get_stylesheet_directory_uri() .'/editor-script.js' );
}
add_action( 'enqueue_block_editor_assets', 'my_theme_editor_container_query' );
?>
@smeric
smeric / add_editor_styles_by_post_id.php
Last active Aug 10, 2021
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).
View add_editor_styles_by_post_id.php
<?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 / f2l-new-type.php
Last active Apr 20, 2020
WordPress plugin to make the displayed WordPress functions names in your posts content clickable and linked to their reference page in the codex using a shortcode.
View f2l-new-type.php
<?php
// as an example, this is the way to add a type to forge links to php.net manual
function F2L_types( $type, $name, $content ) {
if ( 'phpf' === $type ) {
$content = '<code><a href="https://www.php.net/manual/fr/function.' . str_replace( '_', '-', $name ) . '.php" title="' . esc_attr__( 'Check on php.net...', 'txt-domain' ) . '" rel="external noopener noreferrer">' . $name . '</a></code>';
}
return $content;
}
add_filter( 'F2L_types', 'F2L_types', 10, 3 );
@smeric
smeric / editor-style.css
Last active Apr 20, 2020
WordPress Gutengerg starter editor stylesheet. See https://sebastien-meric.com/wordpress-gutenberg-feuille-de-style-editeur/ (in french).
View editor-style.css
/**
* Gutenberg backoffice common content stylesheet
*
* Do note that every CSS declarations will be prepended with .editor-styles-wrapper class.
**/
/** =Bugs
*************************************/
/* @see https://wordpress.org/support/topic/many-new-bugs-after-update/ */
@smeric
smeric / custom-post-type-specific-editor-style.php
Last active May 18, 2020
Add a post-type specific editor stylesheet to each post edit screen in WordPress back-end. See https://sebastien-meric.com/wordpress-gutenberg-feuille-de-style-specifique-type-de-contenu-post-type/ (in french).
View custom-post-type-specific-editor-style.php
<?php
/**
* Registers a specific editor stylesheet for the current post type.
*
* @see https://developer.wordpress.org/reference/functions/add_editor_style/
*/
function my_theme_add_editor_styles() {
global $pagenow, $current_screen;
// Current post-type