Display attribute on shop page after the title

add_filter( ‘the_title’, ‘YearOfMake’, 10, 2 ); function YearOfMake( $title, $post_id ) { if ( get_post_type( $post_id ) != ‘product’ && ! is_archive() ) return $title; if ( ! ( is_shop() || is_product_category() || is_product_tag() ) ) return $title; /* global $product; $attribute=”year-made”; $abv = $product->get_attribute($attribute); if(!empty($abv)) { $title .= ‘<br /><p>’ . $abv . ‘</p>’; … Read more

How can I compel alphanumeric entries for username textbox on woocommerce registration form

You can use the woocommerce_registration_errors hook to validate the username & set an error if your conditions aren’t met – WooCommerce will bail and pass the error back to the UI for the user: add_filter( ‘woocommerce_registration_errors’, function ( WP_Error $errors, $username ) { if ( ! preg_match( ‘/[a-z]/i’, $username ) ) { $errors->add( ‘username’, ‘Username … Read more

How it it possible to disbale all WooCommerce scripts and styles, but keep wc-ajax=get_refreshed_fragments working? [closed]

If you look how that script is loaded in WC core ‘wc-cart-fragments’ => array( ‘src’ => self::get_asset_url( ‘assets/js/frontend/cart-fragments’ . $suffix . ‘.js’ ), ‘deps’ => array( ‘jquery’, ‘js-cookie’ ), ‘version’ => WC_VERSION, ), You’ll see the path to that script, as well as it’s dependencies. rebuild that path and enqueue it yourself. FYI $suffix is … Read more

Hide prices from certain category in woocommerce

The is_category() method checks whether the current query is for an existing category archive page. Being woocommerce you should use the is_product_category() method instead, and to check for single product the has_term($slug, ‘product_cat’, $product_id) method. This code will remove prices from archive pages and single product pages: add_action( ‘woocommerce_after_shop_loop_item_title’, ‘hide_loop_product_prices’, 1 ); function hide_loop_product_prices(){ global … Read more

add referrer to woo

The code in the original article is broken, and would’ve been broken when it was written. So being outdated is not the problem (2 years is nothing in WordPress time). The issue is this line: add_action(‘woocommerce_checkout_update_order_meta’, ‘add_referral_meta’); The callback function they’ve created, add_referral_meta(), accepts two arguments, $order_id and $posted: function add_referral_meta( $order_id, $posted ) { … Read more

How can I reference external attachments without breaking core WordPress files?

Pay attention to the comments along the snippet. <?php /** * Filters the attachment URL. * * @param string $url URL for the given attachment. * @param int $att_id Attachment post ID. * * @return string $url Custom URL for the given attachment. */ function wp_get_attachment_url_callback( $url, $att_id ) { // Instead of keeping full … Read more

Personalize checkout text

If you look at the WooCommerce docs, you’ll see that you can override template parts by having a replacement file in a woocommerce folder in your theme. A lot of the text you’re talking about is hardcoded into woocommerce > templates > checkout > review-order.php Copy that file and modify as needed. Normally I would … Read more

Woocommerce image sizes missing from Appearance › Customize but not declared by theme

WooCommerce itself registers support for the default themes. For Twenty Fifteen it registers the following: add_theme_support( ‘wc-product-gallery-zoom’ ); add_theme_support( ‘wc-product-gallery-lightbox’ ); add_theme_support( ‘wc-product-gallery-slider’ ); add_theme_support( ‘woocommerce’, array( ‘thumbnail_image_width’ => 200, ‘single_image_width’ => 350, ) ); This is why those settings are not in the Customiser. However, regardless of what theme support is registered, the gallery_thumbnail_image_width … Read more