global $product;
// если товар вариантивный
if ($product->is_type( 'variable' ))
{
//получаем варианты
$available_variations = $product->get_available_variations();
foreach ($available_variations as $key => $value)
{
$metadata = $value->get_meta_data();
var_dump($metadata);
}
}
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.my-site\.ru$
RewriteRule ^ https://%1.my-site.ru%{REQUEST_URI} [NE,L,R]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.example\.com$
RewriteRule ^ https://%1.example.com%{REQUEST_URI} [NE,L,R]
add_action('wp_head', function(){
echo "<script>alert('Hello!');</script>";
});
add_filter( 'next_image_link', function($link){
if(empty($link)){
$first_link = '';
$images = get_posts(
[
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_parent' => get_the_ID(),
'posts_per_page' => 1,
]
);
if ( isset($images[0]->ID) ) {
$first_link = '<img src="' . wp_get_attachment_image_src( $images[0]->ID, 'post-thumbnail' ) . '" alt="" />';
}
return $first_link;
}
return $link;
});
add_filter( 'next_image_link', function($link){
if(empty($link)){
$first_link = //тут получаешь ссылку на первую прикрепленную к посту картинку
return $first_link;
}
return $link;
});
$variation = new WC_Product( $value['variation_id'] );
$metadata = $variation->get_meta_data();
var_dump($metadata);