Skip to content

Instantly share code, notes, and snippets.

@CarlosLongarela
Last active May 31, 2019 16:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlosLongarela/69ec6fba4cbe97b15320c8bfd4ebb760 to your computer and use it in GitHub Desktop.
Save CarlosLongarela/69ec6fba4cbe97b15320c8bfd4ebb760 to your computer and use it in GitHub Desktop.
Delete WordPress WooCommerce ld+json price for hide in snippets like Google results
<?php
function cl_product_delete_meta_price( $product = null ) {
if ( ! is_object( $product ) ) {
global $product;
}
if ( ! is_a( $product, 'WC_Product' ) ) {
return;
}
if ( '' !== $product->get_price() ) {
$shop_name = get_bloginfo( 'name' );
$shop_url = home_url();
$markup_offer = array(
'@type' => 'Offer',
'availability' => 'https://schema.org/' . $stock = ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
'sku' => $product->get_sku(),
'image' => wp_get_attachment_url( $product->get_image_id() ),
'description' => $product->get_description(),
'seller' => array(
'@type' => 'Organization',
'name' => $shop_name,
'url' => $shop_url,
),
);
}
return $markup_offer;
}
add_filter( 'woocommerce_structured_data_product_offer', 'cl_product_delete_meta_price' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment