• Hi!

    Been searching in the forums, but I can’t really find anything directly related to my question (and the forums are way harder to navigate nowadays).

    I’m using a theme by Mikado called Cortex and woocommerce.
    They’re using a function for overriding the regular “out of stock” badge and as you can see belo2, they’ve also overridden the text from “out of stock” to just “sold”. I find this a bit misleading.

    Now, I know I can change it in the theme functions file and wait for a theme update to erase it, but it’s not optimal so I’m looking for another solution.

    I’ve been trying to find a function (because I’m not php-savvy, unfortunately) that overrides the text override to “sold out” or back to “out of stock”, without changing anything else with the badge.

    if (!function_exists('cortex_mikado_woocommerce_out_of_stock_flash')) {
    	/**
    	 * Function for overriding Out of Stock badge
    	 *
    	 * @return string
    	 */
    	function cortex_mikado_woocommerce_out_of_stock_flash() {
    
    		global $product;
    		$availability = $product->get_availability();
    
    		if ( !$product->is_in_stock() && WC_Admin_Settings::get_option( 'woocommerce_notify_no_stock')=='yes') {
    			print apply_filters( 'woocommerce_stock_html', '<span class="mkdf-product-badge mkdf-out-of-stock ' . esc_attr( $availability['class'] ) . '"><span class="mkdf-product-badge-inner mkdf-out-of-stock-inner">' . esc_html__('Sold', 'cortex') . '</span></span>', $availability['availability'] );
    		}
    	}
    
    }

    I have a custom-functions plugin installed, instead of a child theme, because I hardly ever change anything other than css.
    Is this enough info for anyone to help me, or do I need to provide more?

    Kind regards!

    • This topic was modified 7 years, 3 months ago by The Doctor.
Viewing 4 replies - 1 through 4 (of 4 total)
  • I might suggest looking at a way to change it just with jQuery on the front end, or use a child theme. A child these in this situation may really make it easier, and it is okay to use a child theme that does nothing except CSS customization and provide functions.php for updates if needed.

    Hopefully that gives a start, but let me know…

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Howdy!

    So… I do want to ask the question of what kind of custom-functions plugin? Is it for only PHP?

    I ask because looking at that code snippet I can see a possible solution. One would be using the filter woocommerce_stock_html for that though I’m not entirely sure they are using the correct filter. O_o

    I know WooCommerce does have quite a bit of action hooks and filters that will help too. I had to look up which one since it was irkin me to see that. 😀

    The correct filter would be woocommerce_get_stock_html

    You could potentially use something like:

    
    add_filter( 'woocommerce_get_stock_html', function( $string, $product ) {
    	// get this so we can use the class later.
    	$avail = $product->get_availability();
    
    	// return the markup that will be seen on the front-end.
    	return sprintf( '<span class="mkdf-product-badge mkdf-out-of-stock %1$s">
    		<span class="mkdf-product-badge-inner mkdf-out-of-stock-inner">
    		%2$s
    		</span></span>', $avail['class'], esc_html__( 'what you want to say', 'text-domain' ) );
    }, 100, 2 );
    

    Please note that code will work for PHP version 5.3 and higher. Hope that helps you out a bit. 🙂

    Thread Starter The Doctor

    (@panicky)

    @jcastaneda
    Thank you!

    I tried your suggestion and dabbled around a bit, but couldn’t get it to work, so I cracked and did as @phillipburger said and created a child theme, simply copying and changing the text.

    this is the plugin I regularly use for function changes.
    https://ww.wp.xz.cn/plugins/my-custom-functions/

    Thanks for your help, have a great weekend!

    @panick – appreciate the reply. I think you will find that even a super simple child theme is going to really help all over the place. I have a child theme that I created and put in a ZIP file so after I upload a parent theme I just upload that file and go to Editor to change a few line in the empty CSS. It is just the CSS and functions.php file and then everything else acts like it is not there.

    When you need the function or simple CSS overwrite, you can just do it easily.

    If you feel the problem is resolved, please resolve this ticket.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Override an overriding function’ is closed to new replies.