Status stok tersuai, seperti "Prepesanan" dan "Hubungi kami ," tiada daripada pilihan produk dalam WooCommerce 4 .
Tambahkan kod berikut pada fail functions.php anda:
// Add new stock status options add_filter( 'woocommerce_product_stock_status_options', 'filter_woocommerce_product_stock_status_options', 10, 1 ); function filter_woocommerce_product_stock_status_options( $status ) { $status['pre_order'] = __( 'Pre order', 'woocommerce' ); $status['contact_us'] = __( 'Contact us', 'woocommerce' ); return $status; } // Availability text add_filter( 'woocommerce_get_availability_text', 'filter_woocommerce_get_availability_text', 10, 2 ); function filter_woocommerce_get_availability_text( $availability, $product ) { switch( $product->get_stock_status() ) { case 'pre_order': $availability = __( 'Pre order', 'woocommerce' ); break; case 'contact_us': $availability = __( 'Contact us', 'woocommerce' ); break; } return $availability; } // Availability CSS class add_filter( 'woocommerce_get_availability_class', 'filter_woocommerce_get_availability_class', 10, 2 ); function filter_woocommerce_get_availability_class( $class, $product ) { switch( $product->get_stock_status() ) { case 'pre_order': $class = 'pre-order'; break; case 'contact_us': $class = 'contact-us'; break; } return $class; } // Admin stock html add_filter( 'woocommerce_admin_stock_html', 'filter_woocommerce_admin_stock_html', 10, 2 ); function filter_woocommerce_admin_stock_html( $stock_html, $product ) { switch( $product->get_stock_status() ) { case 'pre_order': $stock_html = '<mark class="pre-order" style="background:transparent none;color:#33ccff;font-weight:700;line-height:1;">' . __( 'Pre order', 'woocommerce' ) . '</mark>'; break; case 'contact_us': $stock_html = '<mark class="contact-us" style="background:transparent none;color:#cc33ff;font-weight:700;line-height:1;">' . __( 'Contact us', 'woocommerce' ) . '</mark>'; break; } return $stock_html; }
Nota Tambahan:
Atas ialah kandungan terperinci Bagaimana untuk Menambah Status Stok Tersuai seperti 'Prepesanan' dan 'Hubungi Kami' pada Produk WooCommerce?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!