is_purchasable()
|| ! $product->is_in_stock()
|| ! Subscription_Product::is_subscription( $product )
) {
return (string) $text;
}
return self::button_text();
}
public function on_product_page(): void {
global $product;
if ( $product instanceof \WC_Product && Subscription_Product::is_subscription( $product ) ) {
echo wp_kses_post( $this->disclosure->render( $product ) );
}
}
/**
* Everywhere WooCommerce prints a price: product page, shop, category, related products.
*
* @param string $html
* @param mixed $product
*/
public function price_html( $html, $product ): string {
return $product instanceof \WC_Product
? $this->disclosure->price_html( (string) $html, $product )
: (string) $html;
}
/**
* Per line item, because a cart can hold recurring and one-off products together.
*/
public function on_cart_line( $price_html, $cart_item, $cart_item_key ) {
$terms = is_array( $cart_item ) && Subscription_Product::cart_item_is_subscription( $cart_item, (string) $cart_item_key )
? Line_Terms::for_cart_item( $cart_item, (string) $cart_item_key )
: null;
if ( ! $terms ) {
return $price_html;
}
return $price_html . '' . esc_html( wp_strip_all_tags( $this->disclosure->price_line( $cart_item['data'], $terms ) ) ) . '';
}
public function on_checkout_totals(): void {
foreach ( $this->subscription_lines_in_cart() as list( $product, $terms ) ) {
echo '
| ' . esc_html__( 'Recurring', 'submex' ) . ' | '
. wp_kses_post( $this->disclosure->price_line( $product, $terms ) ) . ' |
';
}
}
/**
* The sentence next to the Place Order button — the one that legally matters.
*/
public function before_place_order(): void {
$lines = $this->subscription_lines_in_cart();
if ( empty( $lines ) ) {
return;
}
list( $product, $terms ) = $lines[0];
// Amounts arrive wrapped in so RTL cannot reorder them.
echo '' . wp_kses( $this->disclosure->sentence( $product, $terms ), array( 'bdi' => array() ) ) . '
';
}
public function styles(): void {
if ( ! is_product() && ! is_cart() && ! is_checkout() ) {
return;
}
wp_register_style( 'submex-frontend', false, array(), SUBMEX_VERSION );
wp_enqueue_style( 'submex-frontend' );
wp_add_inline_style(
'submex-frontend',
'.submex-disclosure{margin:1em 0}
.submex-disclosure__facts{list-style:none;margin:0;padding:0;font-size:.9em;line-height:1.6;opacity:.85}
.submex-cart-terms{display:block;font-size:.85em;opacity:.8}
.submex-checkout-consent{margin:0 0 1em;font-size:.9em}
.submex-blocks-disclosure{padding:1em 0;border-top:1px solid rgba(0,0,0,.1)}
.submex-blocks-disclosure__price{font-weight:600;margin:0 0 .35em}
.submex-blocks-disclosure__facts{list-style:none;margin:0;padding:0;font-size:.9em;line-height:1.6;opacity:.85}
.submex-blocks-disclosure__consent{margin:.75em 0 0;font-size:.85em}'
);
}
/**
* @return array
*/
private function subscription_lines_in_cart(): array {
$lines = array();
foreach ( Subscription_Product::cart_subscription_items() as $key => $item ) {
$terms = Line_Terms::for_cart_item( $item, $key );
if ( $terms ) {
$lines[] = array( $item['data'], $terms );
}
}
return $lines;
}
}