Skip to content

Instantly share code, notes, and snippets.

View FrancoStino's full-sized avatar
🌞

Davide Ladisa FrancoStino

🌞
View GitHub Profile
@FrancoStino
FrancoStino / Display List of Products With No Gallery Image @ WP Dashboard > Products.php
Created February 27, 2021 19:35
Display List of Products With No Gallery Image @ WP Dashboard > Products
@FrancoStino
FrancoStino / Combine multiple array.php
Last active March 1, 2021 14:37
Combine multiple array
<?php
$livello1 = array("100");
$descrizione1 = array("In ottone");
foreach(array_combine($livello1, $descrizione1) as $livello => $descrizione)
{
echo '"/\\\b'.$livello.'\\\b/",'; # "\\b" serve per comprendere l'intera singola stringa e metcharla
@FrancoStino
FrancoStino / Replace exact string array with preg_replace.php
Created March 1, 2021 14:40
Replace exact string array with preg_replace
<?php
function livello1($replace){
/*
* Uso " \\b " per prendere esattamente la stringa interessata
*/
$livello1 = array("/\\b0100\\b/","/\\b0120\\b/","/\\b0200\\b/","/\\b0220\\b/","/\\b0240\\b/","/\\b0260\\b/","/\\b0265\\b/","/\\b0270\\b/","/\\b0280\\b/","/\\b0290\\b/","/\\b0300\\b/","/\\b0400\\b/","/\\b0410\\b/","/\\b0600\\b/","/\\b0620\\b/","/\\b0640\\b/","/\\b0660\\b/","/\\b0680\\b/","/\\b0700\\b/","/\\b0720\\b/","/\\b0900\\b/","/\\b0920\\b/","/\\b0950\\b/","/\\b3500\\b/");
@FrancoStino
FrancoStino / Insert content with shortcode if product is bought by customer into product.php
Created March 10, 2021 09:55
Insert content with shortcode if product is bought by customer into product
<?
/*
* Insert content with shortcode if product is bought by customer into product
*/
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
@FrancoStino
FrancoStino / Create button for insert shortcode into TinyMCE.php
Last active September 11, 2022 11:39
Create button for insert shortcode into TinyMCE
<?php
// init process for registering our button
add_action('admin_init', 'wpse72394_shortcode_button_init');
function wpse72394_shortcode_button_init() {
//Abort early if the user will never see TinyMCE
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') && get_user_option('rich_editing') == 'true')
return;
@FrancoStino
FrancoStino / Shortcode Javascript for button TinyMCE.js
Created March 10, 2021 14:16
Shortcode Javascript for button TinyMCE
jQuery(document).ready(function($) {
tinymce.create('tinymce.plugins.wpse72394_plugin', {
init : function(ed, url) {
// Register command for when button is clicked
ed.addCommand('wpse72394_insert_shortcode', function() {
selected = tinyMCE.activeEditor.selection.getContent();
if( selected ){
//If text is selected when button is clicked
@FrancoStino
FrancoStino / WooCommerce – Display purchased products in My Account.php
Created March 12, 2021 10:37
WooCommerce – Display purchased products in My Account
<?
add_filter ( 'woocommerce_account_menu_items', 'misha_purchased_products_link', 40 );
add_action( 'init', 'misha_add_products_endpoint' );
add_action( 'woocommerce_account_purchased-products_endpoint', 'misha_populate_products_page' );
// here we hook the My Account menu links and add our custom one
function misha_purchased_products_link( $menu_links ){
// we use array_slice() because we want our link to be on the 3rd position
@FrancoStino
FrancoStino / WooCommerce Product Reviews Shortcode.php
Last active August 27, 2022 09:13
WooCommerce Product Reviews Shortcode
<?php
// WooCommerce Product Reviews Shortcode
add_shortcode( 'product_reviews', 'bbloomer_product_reviews_shortcode' );
function bbloomer_product_reviews_shortcode() {
$args = array(
'status' => 'approve',
@FrancoStino
FrancoStino / Show Out of stock products at the end in Woocommerce.php
Created March 25, 2021 11:06
Show Out of stock products at the end in Woocommerce
<?
/*
* Show Out of stock products at the end in Woocommerce
*/
add_filter('posts_clauses', 'order_by_stock_status');
function order_by_stock_status($posts_clauses) {
global $wpdb;
// only change query on WooCommerce loops
@FrancoStino
FrancoStino / Display Discount Price Save @ Global Page - Product - Cart - WooCommerce.php
Last active March 29, 2021 09:10
Display Discount Price Save @ Global Page - Product - Cart - WooCommerce
<?
/**
* @snippet Display Discount Percentage @ Loop Pages - WooCommerce
*/
// For simple products
add_filter( 'woocommerce_get_price_html', 'simple_product_saving_amount', 11, 2 );
function simple_product_saving_amount($price_html, $product) {