wc_autoship_price (filter)

Modify the Autoship Price for a product.

Example

Calculate the Autoship Price as 70% of the regular product price.

<?php
/**
 * @param float $autoship_price
 * @param int $product_id
 * @param int $autoship_frequency
 * @param int $customer_id
 * @param int $schedule_item_id
 * @return float
 */
function wc_autoship_price_example( $autoship_price, $product_id, $autoship_frequency, $customer_id, $schedule_item_id ) {
	// Get the product
	$product = wc_get_product( $product_id );
	if ( empty( $product ) ) {
		// Return default
		return $autoship_price;
	}
	// Get the regular price
	$price = $product->get_price();
	// Calculate the Autoship price of 70% of the regular price
	$autoship_discount_price = 0.7*$price;
	return $autoship_discount_price;
}
add_filter( 'wc_autoship_price', 'wc_autoship_price_example', 10, 5 );

Still need help? Contact Us Contact Us