Last active
April 7, 2023 23:47
-
-
Save voronkovich/c6d5735b4430e0907cc84e9aad59ee3e to your computer and use it in GitHub Desktop.
WooCommerce EDI 1C: Настройки и исправления ошибок плагина
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 <[email protected]> | |
* 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