How to Display Stock Status Availability for External Product in WooCommerce WordPress

preview_player
Показать описание
In this woocommerce tutorial for beginners you will learn how to show stock status for single external product page using custom php snippet in wordpress website.
So first enable custom fields from screen options in products page then add text " externalstock " in name field and " 1 or 0 " in value field.
then we will use that externalstock text in custom code.

* Find Code in Top Pinned Comment Section.

In code 1 for in stock text and 0 for out of stock.

#woocommerce #instock #outofstock #stock #externalproduct #product #wordpress #wordpresstutorial #webtaskwithhassan #hassangilani
Рекомендации по теме
Комментарии
Автор

Use this code and add externalstock with value 1 or 0 in custom fields:

add_action( 'woocommerce_external_add_to_cart', 'wtwh_external_product_stock', 29 );

function wtwh_external_product_stock() {
global $product;
$stock_status = get_post_meta( $product->get_id(), 'externalstock', true );

if ( $stock_status == 1 ) {
$availability = __( 'In stock', 'woocommerce' );
$class = 'in-stock';
}
else if ( $stock_status == 0 ) {
$availability = __( 'Out of stock', 'woocommerce' );
$class = 'out-of-stock';
}
wc_get_template(
'single-product/stock.php',
array(
'product' => $product,
'class' => $class,
'availability' => $availability,
)
);
}

WebTaskWithHassan