Product::purchase_button()
Summary
No summary available.Source
File: src/BigCommerce/Post_Types/Product/Product.php
public function purchase_button() { $options = $this->has_options() || $this->out_of_stock() ? 'disabled="disabled"' : ''; $preorder = $this->availability() === Availability::PREORDER; $cart = get_option( Cart::OPTION_ENABLE_CART, true ); $class = 'bc-btn bc-btn--form-submit'; /** * Filters purchase button attributes. * * @param array $attributes Attributes. * @param Product $product Product. */ $attributes = apply_filters( 'bigcommerce/button/purchase/attributes', [], $this ); $attributes = implode( ' ', array_map( function ( $attribute, $value ) { $attribute = sanitize_title_with_dashes( $attribute ); $value = esc_attr( $value ); return sprintf( '%s="%s"', $attribute, $value ); }, array_keys( $attributes ), $attributes ) ); if ( $preorder ) { $class .= ' bc-btn--preorder'; } if ( $cart ) { $class .= ' bc-btn--add_to_cart'; $label = $preorder ? get_option( Buttons::PREORDER_TO_CART, __( 'Add to Cart', 'bigcommerce' ) ) : get_option( Buttons::ADD_TO_CART, __( 'Add to Cart', 'bigcommerce' ) ); } else { $class .= ' bc-btn--buy'; $label = $preorder ? get_option( Buttons::PREORDER_NOW, __( 'Pre-Order Now', 'bigcommerce' ) ) : get_option( Buttons::BUY_NOW, __( 'Buy Now', 'bigcommerce' ) ); } $button = sprintf( '<button class="%s" type="submit" data-js="%d" %s %s>%s</button>', $class, $this->bc_id(), $options, $attributes, $label ); /** * Filters purchase button. * * @param string $button Button html. * @param int $post_id Post id. * @param string $label Label. */ return apply_filters( 'bigcommerce/button/purchase', $button, $this->post_id, $label ); }