返信先: 商品画像情報を編集するフィルターフック

フォーラム 使い方全般 商品画像情報を編集するフィルターフック 返信先: 商品画像情報を編集するフィルターフック

#86011
hiromaya
参加者

ご返信ありがとうございます。

ご教示いただいた通り、usces_the_itemImageURLをもとにユーザー定義関数を作成することにより、商品画像URLのドメインを置換することができました。

以下、備忘録としてコードを貼り付けいたします。

/* 商品URL置換関数 */
function replacement_the_itemImageURL($number = 0, $out = ”, $post = ” ) {
global $usces;
$ptitle = $number;

if( $ptitle && is_string($number) ){
$picposts = query_posts(array(‘post_type’=>’attachment’,’name’=>$ptitle));
if( !$picposts ){
return ”;
}
$pictid = empty($picposts) ? 0 : $picposts[0]->ID;
$pictid = $picposts[0]->ID;
$html = wp_get_attachment_url( $pictid );
}else{

if($post == ”) global $post;
$post_id = $post->ID;

$code = get_post_meta($post_id, ‘_itemCode’, true);
if(!$code) return false;
$name = get_post_meta($post_id, ‘_itemName’, true);
if( 0 == $number ){
$pictid = (int)$usces->get_mainpictid($code);
$html = wp_get_attachment_url( $pictid );
$replace = array(
‘example.com’ => ‘abc12345cdn.com’
);
$replace_html = str_replace(array_keys($replace), $replace, $html);

}else{
$pictids = $usces->get_pictids($code);
$ind = $number – 1;
$pictid = ( isset($pictids[$ind]) && (int)$pictids[$ind] ) ? $pictids[$ind] : 0;
$html = wp_get_attachment_url( $pictid );
$replace = array(
‘example.com’ => ‘abc12345cdn.com’
);
$replace_html = str_replace(array_keys($replace), $replace, $html);
}
}

if($out == ‘return’){
return $replace_html;
}else{
echo $replace_html;
}

}