Skip to content

Instantly share code, notes, and snippets.

<?php
rs::metabox(array(
'title' => 'Select custom date sale',
'layout' => 'none',
'rules' => array(
'post_type' => 'product'
),
'context' => 'normal',
'priority' => 'default',
'controls' => array(
@KoolPal
KoolPal / tracking-info-to-wc-order.php
Created February 21, 2020 06:39 — forked from damiencarbery/add-an-post-tracking-provider.php
Tracking Info to WooCommerce order - Use CMB2 to add a custom metabox to add tracking information to WooCommerce orders. The information is then added to the "Completed Order" email. https://www.damiencarbery.com/2020/01/add-tracking-info-to-woocommerce-order/
<?php
/*
Plugin Name: Tracking Info to WooCommerce order
Plugin URI: https://www.damiencarbery.com/2020/01/add-tracking-info-to-woocommerce-order/
Description: Use CMB2 to add a custom metabox to add tracking information to WooCommerce orders. The information is then added to the "Completed Order" email.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.2
$Id: tracking-info-to-wc-order.php 4947 2020-01-04 14:52:28Z damien $
@KoolPal
KoolPal / woo-close-store.php
Created February 21, 2020 06:38 — forked from gabriserra/woo-close-store.php
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
/**
* 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'])) {
/**
* 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) ";
<?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
@KoolPal
KoolPal / functions.php
Last active February 5, 2020 12:28 — forked from felipe-pita/functions.php
Woocommerce - Remove products from Filter where the variation is out of stock - Replace size with your variation attribute slug
/**
* Remove produtos que a variação não tem em estoque
* Removes products from Filter where the variation is out of stock
* @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_size'])) {
global $product;
if ($product->is_type('variable')) {
@KoolPal
KoolPal / robots.txt
Created February 4, 2020 10:29 — forked from deeman/robots.txt
Custom WordpPress/WooCommerce Robots.txt
User-agent: *
Disallow: /wp-admin/
Disallow: /?s=
Disallow: /search/
Allow: /admin/admin-ajax.php
Disallow: /cgi-bin/
Disallow: /wp-content/cache/
Disallow: /trackback/
Disallow: */trackback/
@KoolPal
KoolPal / wc-noindex-nofollow.php
Created February 4, 2020 08:18 — forked from deeman/wc-noindex-nofollow.php
(SEO) WooCommerce "No Index, No Follow" on cart, order, checkout- pages then using YOAST!
function woo_seo_noindex_special_pages () {
global $post;
$woocommerce_pages = array('cart', 'checkout', 'order-received', 'order-tracking',
'my-account', 'logout', 'lost-password', 'mijireh-secure-checkout');
$slug = get_post($post)->post_name;
if (in_array($slug, $woocommerce_pages)) {
echo '<meta name="robots" content="noindex,follow"/>' . "\n";
}
@KoolPal
KoolPal / gist:ba0dce676b522fd8a202c70de0956ff6
Created October 1, 2019 05:51
Retain Quote Billing & Shipping Country ELSE assign Location based on IP (Geolocation)
// 06-05-2019 Retain Quote Billing & Shipping Country ELSE assign Location based on IP (Geolocation)
function remove_checkout_optional_fields_label_script() {
// Only on checkout page
if( ! ( is_checkout() && ! is_wc_endpoint_url() ) ) return;
$optional = '&nbsp;<span class="optional">(' . esc_html__( 'optional', 'woocommerce' ) . ')</span>';
?>
<script>
jQuery(function($){
// On "update" checkout form event remove option to select countries
$(document.body).on('update_checkout', function(){