Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
claudiosanches / functions.php
Last active June 1, 2022 17:20
WooCommerce - Hide the "In stock" message on product page.
<?php
/**
* Hide the "In stock" message on product page.
*
* @param string $html
* @param string $text
* @param WC_Product $product
* @return string
*/
function my_wc_hide_in_stock_message( $html, $text, $product ) {
@frankschrijvers
frankschrijvers / functions.php
Last active July 17, 2021 04:06
Add gallery thumbs to woocommerce shop page
//* Add gallery thumbs to woocommerce shop page
add_action('woocommerce_shop_loop_item_title','wps_add_extra_product_thumbs', 5);
function wps_add_extra_product_thumbs() {
if ( is_shop() ) {
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
@garvs
garvs / wc-assign-other-role-instead-customer.php
Created May 5, 2016 01:15
Assign to new WooCommerce registered user another role instead of customer
/**
* Replace 'customer' role (WooCommerce use by default) with your own one.
**/
add_filter('woocommerce_new_customer_data', 'wc_assign_custom_role', 10, 1);
function wc_assign_custom_role($args) {
$args['role'] = 'subscriber';
return $args;
}
@claudiosanches
claudiosanches / functions.php
Last active February 23, 2018 19:57
WooCommerce - Adding new "My account" registration fields
<?php
/**
* Add new register fields for WooCommerce registration.
*/
function wooc_extra_register_fields() {
?>
<p class="form-row form-row-first">
<label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
@acanza
acanza / wc-custom-stock-message.php
Last active October 27, 2017 03:59
Modifica el texto de aviso de stock en la ficha de producto
// Personaliza texto stock bajo
add_filter( 'woocommerce_stock_html', 'custom_stock_message', 10, 3 );
function custom_stock_message( $availability_html, $stock, $product ){
$num_items_in_stock = $product->total_stock;
$availability = $product->get_availability();
if ( $product->total_stock <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
$new_availability_html = '<p class="stock" style="color: #EA4242;margin-top: 5px;"> ¡Date prisa! Solo nos quedan ' . $num_items_in_stock . ' unidades</p>';
@claudiosanches
claudiosanches / wc-remove-billing-fields.php
Created January 27, 2016 02:07
WooCommerce - Remove billing address, fone and company fields
<?php
/**
* Plugin Name: WooCommerce Remove billing fields
* Description: Remove billing address, fone and company fields from WooCommerce checkout.
* Author: Claudio Sanches
* Author URI: https://claudiosmweb.com
* Version: 0.0.1
* License: GPLv2 or later
*/
@fernandoacosta
fernandoacosta / functions.php
Last active April 2, 2023 18:07
WooCommerce -- limitar venda em determinado CEP
<?php
add_filter( 'woocommerce_package_rates', 'wc_restrict_sales_by_postcode', 10, 2 );
function wc_restrict_sales_by_postcode( $rates, $package ) {
$cep = WC()->customer->get_shipping_postcode();
$cep = preg_replace( "/[^0-9]/", "",$cep );
if ( '95555000' !== $cep ) {
$rates = array();
}
return $rates;
@zergiocosta
zergiocosta / custom_error_msgs.php
Last active September 3, 2020 15:43
Changing login error message (wp-admin)
<?php
// Insert into your functions.php and have fun by creating login error msgs
function guwp_error_msgs() {
// insert how many msgs you want as array items. it will be shown randomly (html is allowed)
$custom_error_msgs = [
'<strong>YOU</strong> SHALL NOT PASS!',
'<strong>HEY!</strong> GET OUT OF HERE!',
];
// get and returns a random array item to show as the error msg
return $custom_error_msgs[array_rand($custom_error_msgs)];
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'http://www.yoururl.com/your-page/' );
exit;
}
}
@codescribblr
codescribblr / custom-variations-select.css
Last active January 5, 2023 20:10
Custom Select Box Replacements for Woocommerce Variations
.woocommerce.single-product .product .summary .variations {
width: 100%;
}
.woocommerce.single-product .product .summary .variations td {
display: block;
width: 100%;
}
.woocommerce.single-product .product .summary .variations td label {
font-family: 'Nunito', Helvetica, Arial, sans-serif;
letter-spacing: 0px;