WPML
ステータス
未解決
報告対象
WPML Multilingual & Multicurrency for WooCommerce 5.3.2
トピックタグ
Bug

問題の概要

WooCommerceステータスダッシュボードウィジェットで、在庫が少ない商品の数が誤って表示される場合があります。この問題は、ウィジェットが商品の翻訳を個別のアイテムとしてカウントするため、商品を翻訳した際に発生します。

回避策

作業を進める前に、サイトの完全なバックアップを必ず作成してください。


  • テーマのfunctions.phpファイルを開きます。

  • 次のコードを追加します:
    add_filter( 'woocommerce_status_widget_low_in_stock_count_pre_query', 'filter_counts' );
    
    function filter_counts( $var ){
    	global $wpdb;
    	$stock   = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
    	$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
    	$lowinstock_count = $wpdb->get_var(
    		$wpdb->prepare(
    			"SELECT COUNT( product_id )
    							FROM {$wpdb->wc_product_meta_lookup} AS lookup
    							INNER JOIN {$wpdb->posts} as posts ON lookup.product_id = posts.ID
    							INNER JOIN  {$wpdb->prefix}icl_translations as translations ON posts.ID=translations.element_id
    							WHERE stock_quantity <= %d
    							AND stock_quantity > %d
    							AND posts.post_status = 'publish'
    							AND translations.source_language_code IS NULL",
    			$stock,
    			$nostock
    		)
    	);
    	return $lowinstock_count;
    }

すべての既知の問題 →