• Resolved gunivortus01

    (@gunivortus01)


    Hi!

    At least temporary, perhaps definitive, I do not sell some books we wrote through ouer own book shop, but link to the publisher’s page where the book can be ordered. (see link).

    But at my page there’s still the ‘not in stock’ (German: nicht vorr?tig) visible.
    How can I get rid of that, as of article number as well?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

    Thread Starter gunivortus01

    (@gunivortus01)

    Thank you very much. I will give it a try.

    Luminus Alabi

    (@luminus)

    Automattic Happiness Engineer

    Hi @gunivortus01,

    As you’re not selling the product from your store, you should not be managing inventory for it.

    You’ll want to go on the inventory tab and deselect the Manage Stock checkbox.

    Also, since you’re pointing customer somewhere else to make the purchase, you can change the product type to External/Affiliate product, which will allow you provide a link to the external site that replaces the “Add to Cart” button.

    Thread Starter gunivortus01

    (@gunivortus01)

    Hi Luminus (@luminus),

    The stock managing was already unchecked, but your tip to use the External/Affiliate product, did it!
    Thanks lo lot!
    Problem solved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove order / in stock information at front end’ is closed to new replies.