Merged in feature/280-dev-dev01 (pull request #21)
auto-patch 280-dev-dev01-2024-01-19T16_41_58 * auto-patch 280-dev-dev01-2024-01-19T16_41_58
This commit is contained in:
@@ -12,6 +12,7 @@ use Automattic\Jetpack\Constants;
|
||||
use Automattic\WooCommerce\Proxies\LegacyProxy;
|
||||
use Automattic\WooCommerce\Utilities\ArrayUtil;
|
||||
use Automattic\WooCommerce\Utilities\NumberUtil;
|
||||
use Automattic\WooCommerce\Internal\ProductImage\MatchImageBySKU;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
@@ -448,6 +449,7 @@ function wc_scheduled_sales() {
|
||||
|
||||
if ( $sale_price ) {
|
||||
$product->set_price( $sale_price );
|
||||
$product->set_date_on_sale_from( '' );
|
||||
} else {
|
||||
$product->set_date_on_sale_to( '' );
|
||||
$product->set_date_on_sale_from( '' );
|
||||
@@ -1656,3 +1658,45 @@ function wc_update_product_lookup_tables_rating_count_batch( $offset = 0, $limit
|
||||
}
|
||||
}
|
||||
add_action( 'wc_update_product_lookup_tables_rating_count_batch', 'wc_update_product_lookup_tables_rating_count_batch', 10, 2 );
|
||||
|
||||
/**
|
||||
* Attach product featured image. Use image filename to match a product sku when product is not provided.
|
||||
*
|
||||
* @since 8.5.0
|
||||
* @param int $attachment_id Media attachment ID.
|
||||
* @param WC_Product $product Optional product object.
|
||||
* @return void
|
||||
*/
|
||||
function wc_product_attach_featured_image( $attachment_id, $product = null ) {
|
||||
$attachment_post = get_post( $attachment_id );
|
||||
if ( ! $attachment_post ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( null === $product && wc_get_container()->get( MatchImageBySKU::class )->is_enabled() ) {
|
||||
// On upload the attachment post title is the uploaded file's filename.
|
||||
$file_name = pathinfo( $attachment_post->post_title, PATHINFO_FILENAME );
|
||||
if ( ! $file_name ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$product_id = wc_get_product_id_by_sku( $file_name );
|
||||
$product = wc_get_product( $product_id );
|
||||
}
|
||||
|
||||
if ( ! $product ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$product->set_image_id( $attachment_id );
|
||||
$product->save();
|
||||
if ( 0 === $attachment_post->post_parent ) {
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $attachment_id,
|
||||
'post_parent' => $product->get_id(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'add_attachment', 'wc_product_attach_featured_image' );
|
||||
|
||||
Reference in New Issue
Block a user