Skip to content

Instantly share code, notes, and snippets.

@KoolPal
KoolPal / gist:136c70d495b4d85601f75bbcc562b3e4
Created June 9, 2017 12:01 — forked from corsonr/gist:c2781c9e0cc086c5047f
WooCommerce: Add customer username to edit/view order admin page
<?php
// Add WooCommerce customer username to edit/view order admin page
add_action( 'woocommerce_admin_order_data_after_billing_address', 'woo_display_order_username', 10, 1 );
function woo_display_order_username( $order ){
global $post;
$customer_user = get_post_meta( $post->ID, '_customer_user', true );
echo '<p><strong style="display: block;">'.__('Customer Username').':</strong> <a href="user-edit.php?user_id=' . $customer_user . '">' . get_user_meta( $customer_user, 'nickname', true ) . '</a></p>';
@KoolPal
KoolPal / WooCommerce Auto update cart after quantity change.php
Created May 5, 2019 07:18 — forked from kamaroly/WooCommerce Auto update cart after quantity change.php
Auto update cart after quantity change. You trigger the click, but the button doesn't have enough time to become enabled, so that is why, by the time you click the second time the button becomes enabled. Remove the "disabled" propriety before triggering the click. This should be added in **footer.php** of your child theme
<?php if (is_cart()) { ?>
<script type="text/javascript">
// Each time quantity in the cart changes, trigger update
// cart option
jQuery('div.woocommerce').on('change', '.qty', function(){
// Make sure the button is enabled before triggering the event
// otherwise this won't work.
jQuery("[name='update_cart']").prop("disabled", false);
jQuery("[name='update_cart']").trigger("click");
});
@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(){
@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 / 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 / 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')) {
<?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) ";
/**
* 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'])) {
@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