Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WooCommerce templates #1904

Merged
merged 12 commits into from Sep 29, 2022
67 changes: 67 additions & 0 deletions inc/woocommerce.php
Expand Up @@ -24,6 +24,11 @@ function understrap_woocommerce_support() {
// Add Bootstrap classes to form fields.
add_filter( 'woocommerce_form_field_args', 'understrap_wc_form_field_args', 10, 3 );
add_filter( 'woocommerce_quantity_input_classes', 'understrap_quantity_input_classes' );
add_filter( 'woocommerce_loop_add_to_cart_args', 'understrap_loop_add_to_cart_args' );

// Add markup.
add_filter( 'woocommerce_loop_add_to_cart_link', 'understrap_loop_add_to_cart_link' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this filter that adds the container around the add to cart button?

add_filter( 'woocommerce_account_menu_item_classes', 'understrap_account_menu_item_classes' );
}
}

Expand Down Expand Up @@ -177,3 +182,65 @@ function understrap_quantity_input_classes( $classes ) {
return $classes;
}
}

if ( ! function_exists( 'understrap_loop_add_to_cart_link' ) ) {
/**
* Wrap add to cart link in container.
*
* @param string $html Add to cart link HTML.
* @return string Add to cart link HTML.
*/
function understrap_loop_add_to_cart_link( $html ) {
return '<div class="add-to-cart-container">' . $html . '</div>';
}
}

if ( ! function_exists( 'understrap_loop_add_to_cart_args' ) ) {
/**
* Add Bootstrap button classes to add to cart link.
*
* @param array<string,mixed> $args Array of add to cart link arguments.
* @return array<string,mixed> Array of add to cart link arguments.
*/
function understrap_loop_add_to_cart_args( $args ) {
if ( isset( $args['class'] ) && ! empty( $args['class'] ) ) {
if ( ! is_string( $args['class'] ) ) {
return $args;
}

// Remove the `button` class if it exists.
if ( false !== strpos( $args['class'], 'button' ) ) {
$args['class'] = explode( ' ', $args['class'] );
$args['class'] = array_diff( $args['class'], array( 'button' ) );
$args['class'] = implode( ' ', $args['class'] );
}

$args['class'] .= ' btn btn-outline-primary';
} else {
$args['class'] = 'btn btn-outline-primary';
}

if ( 'bootstrap4' === get_theme_mod( 'understrap_bootstrap_version', 'bootstrap4' ) ) {
$args['class'] .= ' btn-block';
}

return $args;
}
}

if ( ! function_exists( 'understrap_account_menu_item_classes' ) ) {
/**
* Add Bootstrap classes to the
*
* @param string[] $classes Array of classes added to the account menu items.
* @return string[] Array of classes added to the account menu items.
*/
function understrap_account_menu_item_classes( $classes ) {
$classes[] = 'list-group-item';
$classes[] = 'list-group-item-action';
if ( in_array( 'is-active', $classes, true ) ) {
$classes[] = 'active';
}
return $classes;
}
}
2 changes: 1 addition & 1 deletion woocommerce/cart/cart-empty.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.5.0
*/

Expand Down
6 changes: 3 additions & 3 deletions woocommerce/cart/cart.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.8.0
*/

Expand All @@ -25,8 +25,8 @@
<table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents" cellspacing="0">
<thead>
<tr>
<th class="product-remove">&nbsp;</th>
<th class="product-thumbnail">&nbsp;</th>
<th class="product-remove"><span class="screen-reader-text"><?php esc_html_e( 'Remove item', 'woocommerce' ); ?></span></th>
<th class="product-thumbnail"><span class="screen-reader-text"><?php esc_html_e( 'Thumbnail image', 'woocommerce' ); ?></span></th>
<th class="product-name"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th>
<th class="product-price"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th>
<th class="product-quantity"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></th>
Expand Down
2 changes: 1 addition & 1 deletion woocommerce/cart/proceed-to-checkout-button.php
Expand Up @@ -13,7 +13,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 2.4.0
*/

Expand Down
2 changes: 1 addition & 1 deletion woocommerce/checkout/form-checkout.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.5.0
*/

Expand Down
3 changes: 2 additions & 1 deletion woocommerce/checkout/form-coupon.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.4.4
*/

Expand All @@ -31,6 +31,7 @@
<p><?php esc_html_e( 'If you have a coupon code, please apply it below.', 'woocommerce' ); ?></p>

<p class="form-row form-row-first">
<label for="coupon_code" class="screen-reader-text"><?php esc_html_e( 'Coupon:', 'woocommerce' ); ?></label>
<input type="text" name="coupon_code" class="form-control" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" id="coupon_code" value="" />
</p>

Expand Down
10 changes: 5 additions & 5 deletions woocommerce/checkout/form-pay.php
Expand Up @@ -11,13 +11,13 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 5.2.0
*/

defined( 'ABSPATH' ) || exit;

$item_totals = $order->get_order_item_totals(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$totals = $order->get_order_item_totals(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
?>
<form id="order_review" method="post">

Expand All @@ -40,7 +40,7 @@
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>">
<td class="product-name">
<?php
echo wp_kses_post( apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ) ); // @codingStandardsIgnoreLine
echo wp_kses_post( apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ) );

do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, false );

Expand All @@ -56,8 +56,8 @@
<?php endif; ?>
</tbody>
<tfoot>
<?php if ( $item_totals ) : ?>
<?php foreach ( $item_totals as $total ) : ?>
<?php if ( $totals ) : ?>
<?php foreach ( $totals as $total ) : ?>
<tr>
<th scope="row" colspan="2"><?php echo $total['label']; ?></th><?php // @codingStandardsIgnoreLine ?>
<td class="product-total"><?php echo $total['value']; ?></td><?php // @codingStandardsIgnoreLine ?>
Expand Down
6 changes: 3 additions & 3 deletions woocommerce/checkout/payment.php
Expand Up @@ -11,13 +11,13 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.5.3
*/

defined( 'ABSPATH' ) || exit;

if ( ! is_ajax() ) {
if ( ! wp_doing_ajax() ) {
do_action( 'woocommerce_review_order_before_payment' );
}
?>
Expand Down Expand Up @@ -56,6 +56,6 @@
</div>
</div>
<?php
if ( ! is_ajax() ) {
if ( ! wp_doing_ajax() ) {
do_action( 'woocommerce_review_order_after_payment' );
}
9 changes: 1 addition & 8 deletions woocommerce/global/form-login.php
Expand Up @@ -11,19 +11,13 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.6.0
*/

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;







if ( is_user_logged_in() ) {
return;
}
Expand Down Expand Up @@ -54,7 +48,6 @@
<?php wp_nonce_field( 'woocommerce-login', 'woocommerce-login-nonce' ); ?>
<input type="hidden" name="redirect" value="<?php echo esc_url( $redirect ); ?>" />
<button type="submit" class="btn btn-outline-primary" name="login" value="<?php esc_attr_e( 'Login', 'woocommerce' ); ?>"><?php esc_html_e( 'Login', 'woocommerce' ); ?></button>

</p>
<p class="lost_password">
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php esc_html_e( 'Lost your password?', 'woocommerce' ); ?></a>
Expand Down
37 changes: 0 additions & 37 deletions woocommerce/loop/add-to-cart.php

This file was deleted.

2 changes: 1 addition & 1 deletion woocommerce/loop/orderby.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.6.0
*/

Expand Down
2 changes: 1 addition & 1 deletion woocommerce/myaccount/downloads.php
Expand Up @@ -13,7 +13,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.2.0
*/

Expand Down
2 changes: 1 addition & 1 deletion woocommerce/myaccount/form-edit-account.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.5.0
*/

Expand Down
2 changes: 1 addition & 1 deletion woocommerce/myaccount/form-edit-address.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.6.0
*/

Expand Down
6 changes: 3 additions & 3 deletions woocommerce/myaccount/form-login.php
Expand Up @@ -11,8 +11,8 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @version 4.1.0
* @package WooCommerce\Templates
* @version 6.0.0
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -95,7 +95,7 @@

<?php else : ?>

<p><?php esc_html_e( 'A password will be sent to your email address.', 'woocommerce' ); ?></p>
<p><?php esc_html_e( 'A link to set a new password will be sent to your email address.', 'woocommerce' ); ?></p>

<?php endif; ?>

Expand Down
2 changes: 1 addition & 1 deletion woocommerce/myaccount/form-lost-password.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.5.2
*/

Expand Down
2 changes: 1 addition & 1 deletion woocommerce/myaccount/form-reset-password.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 3.5.5
*/

Expand Down
13 changes: 7 additions & 6 deletions woocommerce/myaccount/my-address.php
Expand Up @@ -11,7 +11,7 @@
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @package WooCommerce\Templates
* @version 2.6.0
*/

Expand Down Expand Up @@ -53,16 +53,17 @@

<?php foreach ( $get_addresses as $name => $address_title ) : ?>

<?php $address = wc_get_account_formatted_address( $name ); ?>

<div class="u-column woocommerce-Address">
<header class="woocommerce-Address-title title">
<h3><?php echo esc_html( $address_title ); ?></h3>
<a href="<?php echo esc_url( wc_get_endpoint_url( 'edit-address', $name ) ); ?>" class="edit"><?php esc_html_e( 'Edit', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( wc_get_endpoint_url( 'edit-address', $name ) ); ?>" class="edit"><?php echo $address ? esc_html__( 'Edit', 'woocommerce' ) : esc_html__( 'Add', 'woocommerce' ); ?></a>
</header>
<address>
<?php
$address = wc_get_account_formatted_address( $name );
echo $address ? wp_kses_post( $address ) : esc_html_e( 'You have not set up this type of address yet.', 'woocommerce' );
?>
<?php
echo $address ? wp_kses_post( $address ) : esc_html_e( 'You have not set up this type of address yet.', 'woocommerce' );
?>
</address>
</div>

Expand Down