Skip to content

Instantly share code, notes, and snippets.

/*
flatsome [ux-countdown] shortcode usage
*/
//Admin side shortcode
[ux_countdown year="2019" month="10" day="30" time="15:00"]
//Add below in functions.php
echo do_shortcode('[ux_countdown year="2019" month="10" day="30" time="15:00"]');
@monecchi
monecchi / mr_wc_new_order_email_recipient.php
Last active December 27, 2024 14:22
WooCommerce New Order Email to different recipient based on customer's city
/**
* Add another email recipient for admin New Order emails if a shippable product is ordered for a specific city
*
* @param string $recipient a comma-separated string of email recipients (will turn into an array after this filter!)
* @param \WC_Order $order the order object for which the email is sent
* @return string $recipient the updated list of email recipients
*/
function mr_wc_conditional_email_recipient( $recipient, $order ) {
// Bail on WC settings pages since the order object isn't yet set yet
// Not sure why this is even a thing, but shikata ga nai
@itzmekhokan
itzmekhokan / country-prefix-billing-phone.php
Created September 3, 2019 18:25
Add country calling code prefix in woocommerce billing phone on change country in checkout
<?php
add_action( 'wp_footer', 'scripts_for_adding_country_prefix_on_billing_phone' );
function scripts_for_adding_country_prefix_on_billing_phone(){
?>
<script type="text/javascript">
( function( $ ) {
$( document.body ).on( 'updated_checkout', function(data) {
var ajax_url = "<?php echo admin_url('admin-ajax.php'); ?>",
country_code = $('#billing_country').val();
var ajax_data = {
<?php
/**
* Ordena produtos fora de estoque no final do catálogo
* source: https://stackoverflow.com/a/44597448
*/
add_filter('posts_clauses', 'order_by_stock_status');
function order_by_stock_status($posts_clauses) {
global $wpdb;
// only change query on WooCommerce loops
/**
* Ordena produtos fora de estoque no final do catálogo
* source: https://stackoverflow.com/a/44597448
*/
add_filter('posts_clauses', 'order_by_stock_status');
function order_by_stock_status($posts_clauses) {
global $wpdb;
// only change query on WooCommerce loops
if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
$posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
@onlinemediamasters
onlinemediamasters / html-table-of-contents.txt
Last active July 29, 2021 13:04
HTML Table Of Contents
<ol>
<li><a href="/permalink/#subheading-1">Subheading 1</a></li>
<li><a href="/permalink/#subheading-2">Subheading 2</a></li>
<li><a href="/permalink/#subheading-3">Subheading 3</a></li>
<li><a href="/permalink/#subheading-4">Subheading 4</a></li>
<li><a href="/permalink/#subheading-5">Subheading 5</a></li>
<li><a href="/permalink/#subheading-6">Subheading 6</a></li>
<li><a href="/permalink/#subheading-7">Subheading 7</a></li>
<li><a href="/permalink/#subheading-8">Subheading 8</a></li>
<li><a href="/permalink/#subheading-9">Subheading 9</a></li>
@lukapaunovic
lukapaunovic / gist:d7178d42885ccf68a20b9aa6cbf6ff21
Created June 20, 2019 14:49
Restore real IP CloudFlare - WordPress (add in wp-config.php)
if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
$http_x_headers = explode( ',', $_SERVER['HTTP_CF_CONNECTING_IP'] );
$_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}
/**
* Não permitir a troca de status de pedidos cancelados.
* Muda o pedido para apovação manual
*/
add_filter( 'woocommerce_before_order_object_save', 'prevent_cancelled_order_status_change', 10, 2 );
function prevent_cancelled_order_status_change( $order, $data_store ) {
$changes = $order->get_changes();
if (isset($changes['status'])) {
/**
* Remove produtos que a variação não tem em estoque
* @see https://github.com/woocommerce/woocommerce/issues/20689
*/
add_action( 'woocommerce_before_shop_loop_item_title', 'remove_out_of_stock_products_from_active_filter' );
function remove_out_of_stock_products_from_active_filter(){
if (isset($_GET['filter_tamanho'])) {
global $product;
if ($product->is_type('variable')) {
$variations = $product->get_available_variations();
@gabriserra
gabriserra / woo-close-store.php
Created March 24, 2019 21:13
Permit to close a Woocommerce store, enabling the use of a message to warn users.
<?php
/*
Plugin Name: Woo Close Store
Plugin URI: https://github.com/gabriserra/woo-close-store
Description: Woo Close Store handle store closing phase.
Version: 0.1
Author: Gabriele Serra
Author URI: https://gabripr0.altervista.org
Text Domain: woo-close-store
License: MIT