Forum Replies Created

Viewing 5 replies - 16 through 20 (of 20 total)
  • You’re welcome!

    Hi.

    All you need to do is add a filter to remove that message. In your active theme’s ‘functions.php’ file you need to add the following code. First, that file is located here: “/wp-content/themes/{yourActiveThemeName}/functions.php”.

    At the very bottom (or wherever you’d like) paste the following code:

    // ----------------- Remove "Dismiss" message from Store Banner -----------------------------------------------------------------
    add_filter('woocommerce_demo_store', 'removeDismissMessageFromStoreBanner', 2, 99);
    
    function removeDismissMessageFromStoreBanner($notice_with_dismiss_message, $notice_without_dismiss_message)
    {
    	echo '<p class="woocommerce-store-notice demo_store">' . wp_kses_post( $notice_without_dismiss_message ) . '</p>';
    }
    // ------------------------------------------------------------------------------------------------------------------------------

    Hi.

    I will need more information regarding the “not in stock” message. Do you know where this is coming from? If you look in your active theme’s ‘functions.php’ file, search for the text “out-of-stock”. That file is located here: “/wp-content/themes/{yourActiveThemeName}”. Do you see anything? If so, please paste the code that you found. Would it happen to look like this?:

    add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_stock', 10 );
    function woocommerce_template_loop_stock() {
        global $product;
        if ( ! $product->managing_stock() && ! $product->is_in_stock() )
            echo '<p class="stock out-of-stock">Not in stock</p>';
    }

    As for the article number. Do the following. In your active theme’s directory, add a folder called “MyClasses” and inside that folder, create a new file called “ProductMetadataEditor.php” and paste the following code in it.:

    <?php
    
    namespace MyClasses;
    
    defined( 'ABSPATH' ) || exit;
    
    /*
        Created:     02/06/2019
        LastUpdated: 02/06/2019
    */
    
    class ProductMetadataEditor
    {
        // Want to remove the article number for a product? Add the product's ID in this array (seperate IDs with a comma)
        // Want to show the article number for a product again? Remove the product's ID from this array
        private $_product_ids_to_remove_article_number_for = array(226);
    
        private $_product_ids_to_remove_outOfStock_message_for = array(226);
    
        public function ShouldRemoveArticleNumber($product_id)
        {
            if (empty($this->_product_ids_to_remove_article_number_for)) {
                return false;
            }
            else {
                return (in_array($product_id, $this->_product_ids_to_remove_article_number_for)); 
            }
        }
    
        // Need more information before using this method:
        public function ShouldRemoveOutOfStockMessage($product_id)
        {
            if (empty($this->_product_ids_to_remove_outOfStock_message_for)) {
                return false;
            }
            else {
                return (in_array($product_id, $this->_product_ids_to_remove_outOfStock_message_for)); 
            }
        }
    }

    Now, you need to override a WooCommerce file (overriding is far better than changing source files directly). The file you need to override is called “meta.php”. First, in your active theme’s directory create a new folder called “woocommerce”. (Make sure it matches the case and spelling exactly). Inside of the “woocommerce” folder you just created, create another folder called “single-product” (again, match exactly). Now, you need to copy the “meta.php” file we’re going to override into this new folder (“single-product”). Go to the following folder to get a copy of the “meta.php” file we’re going to override: “/wp-content/plugins/woocommerce/templates/single-product/meta.php”. Copy that file and paste it inside of the “single-product” folder you created. Now that we have that copied file in the “single-product” folder, we need to make some changes. Highlight everything inside of the “meta.php” you just copied and delete it all. Then, paste all of this code in it:

    <?php
    /**
     * Single Product Meta
     *
     * This template can be overridden by copying it to yourtheme/woocommerce/single-product/meta.php.
     *
     * HOWEVER, on occasion WooCommerce will need to update template files and you
     * (the theme developer) will need to copy the new files to your theme to
     * maintain compatibility. We try to do this as little as possible, but it does
     * happen. When this occurs the version of the template file will be bumped and
     * the readme will list any important changes.
     *
     * @see 	    https://docs.woocommerce.com/document/template-structure/
     * @author 		WooThemes
     * @package 	WooCommerce/Templates
     * @version     3.0.0
     */
    
    use MyClasses\ProductMetadataEditor;
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    include_once(get_stylesheet_directory() . '/MyClasses/ProductMetadataEditor.php');
    
    global $product;
    ?>
    <div class="product_meta">
    
    	<?php do_action( 'woocommerce_product_meta_start' ); ?>
    
    	<?php
    		$product_metadata_editor = new ProductMetadataEditor();
    	?>
    
    	<?php if (!$product_metadata_editor->ShouldRemoveArticleNumber($product->get_id())) : ?>
    
    		<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
    
    			<span class="sku_wrapper"><?php esc_html_e( 'SKU:', 'woocommerce' ); ?> <span class="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' ); ?></span></span>
    
    		<?php endif; ?>
    
    	<?php endif; ?>
    
    	<?php echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>
    
    	<?php echo wc_get_product_tag_list( $product->get_id(), ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', count( $product->get_tag_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>
    
    	<?php do_action( 'woocommerce_product_meta_end' ); ?>
    
    </div>

    Now that everything is in place, I’ll explain a little about what’s going on. In the “ProductMetadataEditor.php” file, you will put the product ID of the products that you wish to hide the article number and the “out of stock” message (once we figure that one out). All you have to do is add the id (the link you provided is for a product with id 226). So, you’ll see 226 inside of the “$_product_ids_to_remove_article_number_for” array. Just add another product’s ID into that array if you want to hide that product’s article number as well. For example, if the next product has ID 227 then you should write in 227 so that it looks like this : “array(226,227)”. There is also another array in that file called “$_product_ids_to_remove_outOfStock_message_for”. It works the same way (just add a product’s ID in that array to remove the “out of stock message”). We need to figure out the “out of stock” message but the article number should disappear from the product that you linked to after you put everything in place.

Viewing 5 replies - 16 through 20 (of 20 total)