Created
May 7, 2021 09:32
-
-
Save AchalJ/68a46bb0b4b3fbbdcf00a4f493d2dc28 to your computer and use it in GitHub Desktop.
Beaver Themer - WooCommerce: Add Stock Status field connection
This file contains 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
add_action( 'fl_page_data_add_properties', 'ac_add_field_connections' ); | |
function ac_add_field_connections() { | |
FLPageData::add_post_property( 'woocommerce_product_stock_status', array( | |
'label' => __( 'Product Image with Gallery Slider', 'woopack' ), | |
'group' => 'woocommerce', | |
'type' => 'string', | |
'getter' => 'ac_get_product_stock_status', | |
) ); | |
} | |
// Currently, not registering setting panel for the field connection. | |
function ac_get_product_stock_status( $settings ) { | |
global $product; | |
$instock = $product->is_in_stock(); | |
$show_status = isset( $settings->show_status ) ? $settings->show_status : ''; | |
$instock_text = isset( $settings->instock_text ) ? $settings->instock_text : __( 'In Stock' ); | |
$outofstock_text = isset( $settings->outofstock_text ) ? $settings->outofstock_text : __( 'Out of Stock' ); | |
if ( $instock && 'instock' === $show_status ) { | |
echo $instock_text; | |
} | |
if ( ! $instock && 'instock' !== $show_status ) { | |
echo $outofstock_text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment