58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Loop Add to Cart
|
|
*
|
|
* @author WooThemes
|
|
* @package WooCommerce/Templates
|
|
* @version 1.6.4
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
|
|
global $product;
|
|
?>
|
|
|
|
<?php if ( ! $product->is_in_stock() ) : ?>
|
|
|
|
<a href="<?php echo apply_filters( 'out_of_stock_add_to_cart_url', get_permalink( $product->id ) ); ?>" class="button"><?php echo apply_filters( 'out_of_stock_add_to_cart_text', __( 'Read More', 'woocommerce' ) ); ?></a>
|
|
|
|
<?php else : ?>
|
|
|
|
<?php
|
|
$link = array(
|
|
'url' => '',
|
|
'label' => '',
|
|
'class' => ''
|
|
);
|
|
|
|
switch ( $product->product_type ) {
|
|
case "variable" :
|
|
$link['url'] = apply_filters( 'variable_add_to_cart_url', get_permalink( $product->id ) );
|
|
$link['label'] = apply_filters( 'variable_add_to_cart_text', __( 'Select options', 'woocommerce' ) );
|
|
break;
|
|
case "grouped" :
|
|
$link['url'] = apply_filters( 'grouped_add_to_cart_url', get_permalink( $product->id ) );
|
|
$link['label'] = apply_filters( 'grouped_add_to_cart_text', __( 'View options', 'woocommerce' ) );
|
|
break;
|
|
case "external" :
|
|
$link['url'] = apply_filters( 'external_add_to_cart_url', get_permalink( $product->id ) );
|
|
$link['label'] = apply_filters( 'external_add_to_cart_text', __( 'Read More', 'woocommerce' ) );
|
|
break;
|
|
default :
|
|
if ( $product->is_purchasable() ) {
|
|
$link['url'] = apply_filters( 'add_to_cart_url', esc_url( $product->add_to_cart_url() ) );
|
|
$link['label'] = apply_filters( 'add_to_cart_text', __( 'Add to cart', 'woocommerce' ) );
|
|
$link['class'] = apply_filters( 'add_to_cart_class', 'add_to_cart_button' );
|
|
} else {
|
|
$link['url'] = apply_filters( 'not_purchasable_url', get_permalink( $product->id ) );
|
|
$link['label'] = apply_filters( 'not_purchasable_text', __( 'Read More', 'woocommerce' ) );
|
|
}
|
|
break;
|
|
}
|
|
|
|
echo apply_filters( 'woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" class="%s button product_type_%s"%s>%s</a>', $link['url'], $product->id, $link['class'], $product->product_type, $product->get_sku() ? ' data-product_sku="' . $product->get_sku() . '"' : '', $link['label'] ), $product, $link );
|
|
|
|
?>
|
|
|
|
<?php endif; ?>
|