Skip to content

Instantly share code, notes, and snippets.

@voronkovich
Last active April 7, 2023 23:47
Show Gist options
  • Save voronkovich/c6d5735b4430e0907cc84e9aad59ee3e to your computer and use it in GitHub Desktop.
Save voronkovich/c6d5735b4430e0907cc84e9aad59ee3e to your computer and use it in GitHub Desktop.
WooCommerce EDI 1C: Настройки и исправления ошибок плагина
<?php
/**
* Plugin Name: WooCommerce EDI 1c: hacks
* Description: Настройки и исправления ошибок плагина
* Version: 0.0.1
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Author: PopArtDesign <info@popartdesign.ru>
* Author URI: https://popartdesign.ru/
*/
defined( 'ABSPATH' ) || exit;
/**
* Удаляет главное изображение товара из галереи.
*/
add_action( 'edi_product_before_save', function ( $product ) {
$featured_image_id = $product->get_image_id();
if ( null === $featured_image_id ) {
return;
}
$gallery_image_ids = $product->get_gallery_image_ids();
if ( 0 === count( $gallery_image_ids ) ) {
return;
}
$gallery_image_ids = array_filter(
$gallery_image_ids,
function ( $image_id ) use ( $featured_image_id ) {
return $image_id !== $featured_image_id;
}
);
$product->set_gallery_image_ids( $gallery_image_ids );
}, PHP_INT_MAX );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment