Filter Uncanny Redemption Codes

ulc_automator_codes_managing_stock

Filters stock status for products managed by the ULCC Automator before it is saved.

add_filter( 'ulc_automator_codes_managing_stock', $callback, 10, 1 );

Description

This filter controls the output of the managing stock status for automator codes. Developers can modify the boolean `true` value to disable or alter the stock management representation, impacting how it's displayed or processed within the WooCommerce Product Automator system.


Usage

add_filter( 'ulc_automator_codes_managing_stock', 'your_function_name', 10, 1 );

Parameters

$this (mixed)
This parameter determines whether stock management is enabled for the product.

Return Value

The filtered value.


Examples

add_filter( 'ulc_automator_codes_managing_stock', 'my_custom_manage_stock_logic', 10, 2 );

/**
 * Conditionally manage stock for specific automator codes.
 *
 * This function demonstrates how to modify the default stock management behavior
 * based on certain conditions. In this example, we'll prevent stock management
 * for automator codes that have a specific meta key set.
 *
 * @param bool   $managing_stock The current value of whether stock is being managed.
 * @param object $product_automator_code The product automator code object instance.
 * @return bool The modified value indicating whether stock should be managed.
 */
function my_custom_manage_stock_logic( $managing_stock, $product_automator_code ) {
	// Check if the automator code object has a meta field 'disable_stock_management' set to true.
	if ( $product_automator_code instanceof WC_Product_Automator_Code ) {
		$disable_stock = get_post_meta( $product_automator_code->get_id(), 'disable_stock_management', true );

		if ( $disable_stock === 'yes' ) {
			// If the meta key is set to 'yes', return false to disable stock management.
			return false;
		}
	}

	// Otherwise, return the original value.
	return $managing_stock;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/includes/wc_product_automator_codes.php:107
src/includes/wc_product_automator_codes.php:114

public function get_manage_stock( $context = 'view' ) {
		return apply_filters( 'ulc_automator_codes_managing_stock', true, $this );
	}


Scroll to Top