woocommerce/templates/loop/add-to-cart.php

60 lines
2.3 KiB
PHP
Raw Normal View History

2011-12-12 11:35:54 +00:00
<?php
/**
* Loop Add to Cart
2012-08-14 18:05:45 +00:00
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
2011-12-12 11:35:54 +00:00
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2012-08-06 23:33:52 +00:00
global $product;
2011-12-12 11:35:54 +00:00
?>
2012-05-26 14:18:29 +00:00
<?php if ( ! $product->is_in_stock() ) : ?>
2012-08-06 23:33:52 +00:00
2012-07-10 14:39:51 +00:00
<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>
2011-12-12 11:35:54 +00:00
2012-05-26 14:18:29 +00:00
<?php else : ?>
2012-08-06 23:33:52 +00:00
<?php
$link = array(
'url' => '',
'label' => '',
'class' => ''
);
2012-08-06 23:33:52 +00:00
$handler = apply_filters( 'woocommerce_add_to_cart_handler', $product->product_type, $product );
switch ( $handler ) {
2012-05-26 14:18:29 +00:00
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' ) );
2012-05-26 14:18:29 +00:00
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' ) );
2012-05-26 14:18:29 +00:00
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' ) );
2012-05-26 14:18:29 +00:00
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' ) );
}
2012-05-26 14:18:29 +00:00
break;
}
2012-08-06 23:33:52 +00:00
2013-02-14 16:50:45 +00:00
echo apply_filters( 'woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="%s button product_type_%s">%s</a>', esc_url( $link['url'] ), esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $link['class'] ), esc_attr( $product->product_type ), esc_html( $link['label'] ) ), $product, $link );
2011-12-12 11:35:54 +00:00
2012-05-26 14:18:29 +00:00
?>
2011-12-12 11:35:54 +00:00
<?php endif; ?>