• Resolved Ali

    (@alishahcheraghi)


    Hi @rilwis
    How do I change <meta property=”og:type” content=”article”> to <meta property=”og:type” content=”product“> in product pages and add this meta tags:

    • product:price:amount
    • product:price:currency
    • product:availability
      Is it possible?

      Thank you

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi @alishahcheraghi ,

    Currently it’s not possible yet. But I’m wondering where do you get these tags from? They’re not in Facebook list nor Open Graph protocol website.

    Thread Starter Ali

    (@alishahcheraghi)

    Plugin Author Anh Tran

    (@rilwis)

    @alishahcheraghi,

    I’ve just added filters for open graph tags and updated the docs with that. Can you please try it?

    Thread Starter Ali

    (@alishahcheraghi)

    @rilwis

    It doesn’t work!

    • This reply was modified 3 years, 2 months ago by Ali.
    Thread Starter Ali

    (@alishahcheraghi)

    add_filter( 'slim_seo_open_graph_type', function( $value, $tag ) {
        if ( is_post( 123 ) ) {
            $value = 'product';
        }
    }, 10, 2 );

    to

    add_filter( 'slim_seo_open_graph_type', function( $value, $tags ) {
        if ( is_product() ) {
            $value = 'product';
        }
    	return $value;
    }, 10, 2 );

    and

    add_action( 'wp_head', function() {
    	
        if ( is_product() ) {
    		
    	global $post, $wp_query;
    	$postID = $wp_query->post->ID;
    	$product = wc_get_product( $postID );
    		
    		
    		 echo '<meta property="product:brand" content="REBOORA" />'. "\n";
    		 echo '<meta property="product:price:amount" content="' . $product->get_price() . '" />'. "\n";
             echo '<meta property="product:price:currency" content="' .get_woocommerce_currency().'" />'. "\n";
    		 echo '<meta property="product:condition" content="new">'. "\n";
    	     echo '<meta property="product:retailer_item_id" content="' . $product->get_sku() . '"/>'. "\n";
    		
    		 {
    		 if ( $product->is_on_backorder() ) {
    			echo '<meta property="og:availability" content="backorder" />' . "\n";
    			echo '<meta property="product:availability" content="available for order" />' . "\n";
    			return;
    		}
    
    		if ( $product->is_in_stock() ) {
    			echo '<meta property="og:availability" content="instock" />' . "\n";
    			echo '<meta property="product:availability" content="in stock" />' . "\n";
    			return;
    		}
    
    		echo '<meta property="og:availability" content="out of stock" />' . "\n";
    		echo '<meta property="product:availability" content="out of stock" />' . "\n";
    		}	
        }
    } );
    • This reply was modified 3 years, 2 months ago by Ali.
    • This reply was modified 3 years, 2 months ago by Ali.
    Plugin Author Anh Tran

    (@rilwis)

    Hi @alishahcheraghi,

    Did you try with the latest commit on Github?

    Thread Starter Ali

    (@alishahcheraghi)

    Hi @rilwis
    I changed some of the code and it worked.

    add_filter( 'slim_seo_open_graph_type', function( $value, $tag ) {
        if ( is_post( 123 ) ) {
            $value = 'product';
        }
    }, 10, 2 );

    should be:

    add_filter( 'slim_seo_open_graph_type', function( $value, $tags ) {
        if ( is_product() ) {
            $value = 'product';
        }
    	return $value;
    }, 10, 2 );

    And I added:

    add_action( 'wp_head', function() {
    	
        if ( is_product() ) {
    		
    	global $post, $wp_query;
    	$postID = $wp_query->post->ID;
    	$product = wc_get_product( $postID );
    		
    		
    		 echo '<meta property="product:brand" content="REBOORA" />'. "\n";
    		 echo '<meta property="product:price:amount" content="' . $product->get_price() . '" />'. "\n";
             echo '<meta property="product:price:currency" content="' .get_woocommerce_currency().'" />'. "\n";
    		 echo '<meta property="product:condition" content="new">'. "\n";
    	     echo '<meta property="product:retailer_item_id" content="' . $product->get_sku() . '"/>'. "\n";
    		
    		 {
    		 if ( $product->is_on_backorder() ) {
    			echo '<meta property="og:availability" content="backorder" />' . "\n";
    			echo '<meta property="product:availability" content="available for order" />' . "\n";
    			return;
    		}
    
    		if ( $product->is_in_stock() ) {
    			echo '<meta property="og:availability" content="instock" />' . "\n";
    			echo '<meta property="product:availability" content="in stock" />' . "\n";
    			return;
    		}
    
    		echo '<meta property="og:availability" content="out of stock" />' . "\n";
    		echo '<meta property="product:availability" content="out of stock" />' . "\n";
    		}	
        }
    } );

    Thanks a lot for your support

    Plugin Author Anh Tran

    (@rilwis)

    Opps, my bad! I forgot to add the return statement.

    Glad that you have it resolved! Let me know if you need any further help.

    PS: I’ll release a new version now.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘og:type’ is closed to new replies.