Last active
June 14, 2021 09:43
-
-
Save hamidrezayazdani/c0e2f0be5142ee12691dca0b09337114 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* add shortcode to wp | |
*/ | |
add_shortcode( 'stock_status', 'display_product_stock_status' ); | |
function display_product_stock_status( $atts) { | |
$atts = shortcode_atts( | |
array('id' => get_the_ID() ), | |
$atts, | |
'stock_status', | |
); | |
$product = wc_get_product( $atts['id'] ); | |
if ( ! $product ) { | |
return null; | |
} | |
return wc_get_stock_html( $product ); | |
} | |
// The code goes to your active theme (or child theme) functions.php | |
/** | |
* Usage: | |
* Place [stock_status id="YOUR PRODUCT ID"] everywhere you want to show stock status | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment