@@ -1523,24 +1523,42 @@ public function get_login_confirmation_settings() {
15231523	}
15241524
15251525	/** 
1526- 	 * Pages where  the express checkout buttons should be displayed . 
1526+ 	 * Check if  the express checkout type is enabled for the given location . 
15271527	 * 
1528- 	 * @return array 
1528+ 	 * @param string $express_checkout_type The type of express checkout. 
1529+ 	 * @param string $location The location to check. 
1530+ 	 * @return boolean 
15291531	 */ 
1530- 	public  function  get_button_locations () {
1531- 		// If the locations have not been set return the default setting. 
1532- 		if  ( ! isset ( $ this  ->stripe_settings ['payment_request_button_locations ' ] ) ) {
1533- 			return  [ 'product ' , 'cart '  ];
1532+ 	public  function  is_enabled_for_location ( $ express_checkout_type  = 'payment_request ' , $ location  = ''  ) {
1533+ 		switch  ( $ express_checkout_type  ) {
1534+ 			case  'payment_request ' :
1535+ 				$ key  = 'payment_request_button_locations ' ;
1536+ 				break ;
1537+ 			case  'link ' :
1538+ 				// Link does not yet have its own Customize page. 
1539+ 				$ key  = 'payment_request_button_locations ' ;
1540+ 				break ;
1541+ 			case  'amazon_pay ' :
1542+ 				$ key  = 'amazon_pay_button_locations ' ;
1543+ 				break ;
1544+ 			default :
1545+ 				$ key  = 'payment_request_button_locations ' ;
1546+ 				break ;
15341547		}
15351548
1536- 		// If all locations are removed through the settings UI the location config will be set to 
1537- 		// an empty string "". If that's the case (and if the settings are not an array for any 
1538- 		// other reason) we should return an empty array. 
1539- 		if  ( ! is_array ( $ this  ->stripe_settings ['payment_request_button_locations ' ] ) ) {
1540- 			return  [];
1549+ 		if  ( ! isset ( $ this  ->stripe_settings [ $ key  ] ) ) {
1550+ 			// If the locations have not been set/modified, return the default setting. 
1551+ 			$ enabled_locations  = [ 'product ' , 'cart '  ];
1552+ 		} elseif  ( ! is_array ( $ this  ->stripe_settings [ $ key  ] ) ) {
1553+ 			// If all locations are removed through the settings UI the location config will be set to 
1554+ 			// an empty string "". If that's the case (and if the settings are not an array for any 
1555+ 			// other reason) we should return an empty array. 
1556+ 			$ enabled_locations  = [];
1557+ 		} else  {
1558+ 			$ enabled_locations  = $ this  ->stripe_settings [ $ key  ];
15411559		}
15421560
1543- 		return  $ this -> stripe_settings [ ' payment_request_button_locations ' ] ;
1561+ 		return  in_array (  $ location ,  $ enabled_locations ,  true  ) ;
15441562	}
15451563
15461564	/** 
@@ -1560,7 +1578,14 @@ public function is_express_checkout_enabled() {
15601578	 * @return boolean 
15611579	 */ 
15621580	public  function  is_payment_request_enabled () {
1563- 		return  $ this  ->gateway ->is_payment_request_enabled ();
1581+ 		$ is_enabled  = $ this  ->gateway ->is_payment_request_enabled ();
1582+ 		if  ( is_product () ) {
1583+ 			return  $ is_enabled  && $ this  ->is_enabled_for_location ( 'payment_request ' , 'product '  );
1584+ 		} elseif  ( is_cart () ) {
1585+ 			return  $ is_enabled  && $ this  ->is_enabled_for_location ( 'payment_request ' , 'cart '  );
1586+ 		}
1587+ 
1588+ 		return  $ is_enabled ;
15641589	}
15651590
15661591	/** 
@@ -1569,7 +1594,14 @@ public function is_payment_request_enabled() {
15691594	 * @return boolean 
15701595	 */ 
15711596	public  function  is_amazon_pay_enabled () {
1572- 		return  WC_Stripe_UPE_Payment_Method_Amazon_Pay::is_amazon_pay_enabled ( $ this  ->gateway  );
1597+ 		$ is_enabled  = WC_Stripe_UPE_Payment_Method_Amazon_Pay::is_amazon_pay_enabled ( $ this  ->gateway  );
1598+ 		if  ( is_product () ) {
1599+ 			return  $ is_enabled  && $ this  ->is_enabled_for_location ( 'amazon_pay ' , 'product '  );
1600+ 		} elseif  ( is_cart () ) {
1601+ 			return  $ is_enabled  && $ this  ->is_enabled_for_location ( 'amazon_pay ' , 'cart '  );
1602+ 		}
1603+ 
1604+ 		return  $ is_enabled ;
15731605	}
15741606
15751607	/** 
0 commit comments