Before you ask please READ THIS

Adding a 'Coming Soon' label to products

in FatMoon Posts: 4
Hi there,
I am looking to add a new label to my product. At the moment I can use the tag 'new' on the product tags, and it will add a NEW label to the product image in the shop (see attached image - upper left hand corner). I'd like to do the same but have it say Coming Soon. Can you please tell me where I am looking to find the code for this?

My site is at https://grimride.com
I am running Fatmoon theme on Wordpress 4.9.6

jason.
GRIMRIDE_NEW.jpg
385 x 385 - 54K

Comments

  • AirAir
    Posts: 10,970
    Hello :-)

    Code for our "new" tag is in fatmoon\advance\utilities\woocommerce.php line ~351:
    //new
                if(apollo13framework_is_product_new()){
                    $html .= '<span class="ribbon new"><em>'.esc_html__( 'New', 'fatmoon' ).'</em></span>';
                }
    You can add your own tag by copying this code below existing one. You could change it like this:
                //coming soon
    	        global $product;
                if(is_object_in_term( apollo13framework_wc_get_product_id($product), 'product_tag', 'coming-soon' )){
                    $html .= '<span class="ribbon coming-soon"><em>'.esc_html__( 'Coming soon', 'fatmoon' ).'</em></span>';
                }
    And now you can add coming-soon tag to your product.

    After you make it work, best would be to make overwrite of this function apollo13framework_wc_single_product_labels() in child theme https://rifetheme.com/apollo13-framework/docs/modifications-of-theme/changing-theme-functions/

    With kind regards.
  • Posts: 4
    Thanks for this I have located the code, and updated the woocommerce.php file as above. Its returning the following error:
    Your PHP code changes were rolled back due to an error on line 357 of file wp-content/themes/fatmoon/advance/utilities/woocommerce.php. Please fix and try saving again.
    
    Call to undefined function apollo13framework_wc_get_product_id()
  • AirAir
    Posts: 10,970
    This function is defined in 274 line in the same file. Please show me the code(it can be screenshot) that you have now. I suspect you have added code outside of function body.

    With kind regards.
  • edited June 2018 Posts: 4
    Thanks Air.
    I got it working, by adding the following code at line 274:
    if(!function_exists('apollo13framework_is_product_coming')){
    	/**
    	 * is current product coming soon
    	 *
    	 * @return bool
    	 */
    	function apollo13framework_is_product_coming() {
            global $product;
            return is_object_in_term( $product->id, 'product_tag', 'coming-soon' );
        }
    }
    Then adding the following code at 366:
                }
    			if(apollo13framework_is_product_coming()){
                    $html .= '<span class="ribbon coming-soon"><em>'.esc_html__( 'Coming Soon', 'apollo13-framework' ).'</em></span>';
                }
    This was how I had placed the code you gave me - which wasn't working:
    if(!function_exists( 'apollo13framework_wc_single_product_labels' )){
    	/**
    	 * add labels above to single product
    	 */
    	function apollo13framework_wc_single_product_labels() {
            global $product;
    
            $html = '';
    
            //labels
            //out of stock
            if(!$product->is_in_stock()){
                $html .= '<span class="ribbon out-of-stock"><em>'.esc_html__( 'Out of stock', 'woocommerce' ).'</em></span>';
            }
            else{
                //sale
                if($product->is_on_sale()){
                    $html .= '<span class="ribbon sale"><em>'.esc_html__( 'Sale', 'apollo13-framework' ).'</em></span>';
                }
                //new
                if(apollo13framework_is_product_new()){
                    $html .= '<span class="ribbon new"><em>'.esc_html__( 'New', 'apollo13-framework' ).'</em></span>';
                }
    			//coming soon
    	        global $product;
                if(is_object_in_term(apollo13framework_wc_get_product_id($product), 'product_tag', 'coming-soon' )){
                    $html .= '<span class="ribbon coming-soon"><em>'.esc_html__( 'Coming soon', 'apollo13framework' ).'</em></span>';
                }
            }
    
    		if(strlen($html)){
    			echo '<div class="product-labels">'.$html.'</div>';
    		}
        }
    }
    add_action( 'woocommerce_before_shop_loop_item_title', 'apollo13framework_wc_single_product_labels', 11);
    Thanks for your help.
    Post edited by Air on
  • AirAir
    Posts: 10,970
    You did in the best way possible! Strange that it wasn't working before, but glad we have found solution together :-)

    WIth kind regards.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion