diff --git a/src/Admin/Options.php b/src/Admin/Options.php index c3cbc94..a8d3d6d 100644 --- a/src/Admin/Options.php +++ b/src/Admin/Options.php @@ -940,6 +940,26 @@ function () { self::SF_FEED_SETTINGS_PAGE, 'sf_feed_settings_categories' ); + + // Get main image from parent without have variant in feed + add_settings_field( + 'get_parent_image_if_empty_in_feed', + __( 'Set the main image of the parent if the variation is blank', 'shopping-feed' ), + function () { + ?> + + + id ); $show_out_of_stock_variations = $for_feed && ShoppingFeedHelper::show_out_of_stock_products_in_feed(); + $check_parent_main_image = ShoppingFeedHelper::check_get_parent_image_if_empty_in_feed(); $variations = []; foreach ( $product->get_children() as $variation_id ) { $variation = wc_get_product( $variation_id ); @@ -479,6 +480,8 @@ public function get_variations( $for_feed = false ) { $variation_data['length'] = $variation->get_length(); if ( ! empty( get_the_post_thumbnail_url( $variation->get_id(), 'full' ) ) ) { $variation_data['image_main'] = get_the_post_thumbnail_url( $variation->get_id(), 'full' ); + } elseif ($check_parent_main_image && ! empty( get_the_post_thumbnail_url( $variation->get_parent_id(), 'full' ) ) ) { + $variation_data['image_main'] = get_the_post_thumbnail_url( $variation->get_parent_id(), 'full' ); } $variation_data['attributes'] = $this->get_variation_attributes( $variation ); diff --git a/src/ShoppingFeedHelper.php b/src/ShoppingFeedHelper.php index 4730130..da98a75 100644 --- a/src/ShoppingFeedHelper.php +++ b/src/ShoppingFeedHelper.php @@ -262,6 +262,15 @@ public static function show_out_of_stock_products_in_feed() { return 'on' === self::get_sf_feed_options( 'out_of_stock_products_in_feed' ); } + /** + * Should the main image of the parent product be collected if the variation image is empty? + * + * @return bool true if you have to make this check, false otherwise. + */ + public static function check_get_parent_image_if_empty_in_feed() { + return 'on' === self::get_sf_feed_options( 'get_parent_image_if_empty_in_feed' ); + } + /** * Return display mode for category * @return string