Payment Gateways: Hide Amazon Pay When Autoship Products Are In the Cart

Hides the Amazon Pay option when 1 or more products selected for Autoship are in the cart

Important: Always test customizations to your site on a staging environment before making changes to your live / production site.  If you are not experienced with testing changes on a staging site, here is a good article to review.

/**
* Disable Amazon Pay when 1+ Autoship Items are in the cart.
* NOTE: This is specific to the WooCommerce Amazon Pay Gateway by WooCommerce
*
* @param bool $enable True if Amazon Pay is enabled else false.
* @return bool The filtered setting.
*/
function xx_hide_amazon_pay_on_autoship( $enable ){

    // if Autoship is not installed or no autoship return original else return based on autoship in cart.
    return ( !function_exists( 'autoship_cart_has_valid_autoship_items' ) || !autoship_cart_has_valid_autoship_items() )?
    $enable : !autoship_cart_has_valid_autoship_items();

}
add_filter( 'woocommerce_amazon_payments_init', 'xx_hide_amazon_pay_on_autoship', 10, 1 );