0

我不是经验丰富的编码员,但我们开始了....我使用 yoast seo 添加开放图元。例如,当我通过 whatsapp 共享 woocommerce 产品时,没有传递产品价格……所以我试图在标题之后添加价格……当然不起作用:-(

function change_yoast_seo_og_meta() {

   add_filter( 'wpseo_opengraph_title', 'change_title' );

}

function change_title( $title ) {

echo $sale_price = get_post_meta( get_the_ID(), '_price', true);


$regular_price = get_post_meta( get_the_ID(), '_regular_price', true);


if ($regular_price == ""){

$available_variations = $product->get_available_variations();

$variation_id=$available_variations[0]['variation_id']; 

$variable_product1= new WC_Product_Variation( $variation_id );

$regular_price = $variable_product1 ->regular_price;
}

   $title = __( $regular_price, 'change_textdomain' );

  return $title;
}
4

0 回答 0