function woocommerce_template_loop_add_to_cart() { global $product; if ($product->product_type == "simple") { woocommerce_simple_add_to_cart(); } else { woocommerce_get_template('loop/add-to-cart.php'); } }
public function simple_add_to_cart() { global $woocommerce, $product; ob_start(); woocommerce_simple_add_to_cart(); $button = ob_get_clean(); /*modify button class so that AJAX add-to-cart script finds it*/ $replacement = sprintf('data-product_id="%d" data-quantity="1" $1 add_to_cart_button product_type_simple ', $product->id); $button = preg_replace('/(class="single_add_to_cart_button)/', $replacement, $button); echo $button; }
/** * customise Add to Cart link/button for product loop * @param string $button * @param object $product * @return string */ function custom_woo_loop_add_to_cart_link($button, $product) { // not for variable, grouped or external products if (!in_array($product->product_type, array('variable', 'grouped', 'external'))) { // only if can be purchased if ($product->is_purchasable()) { // show qty +/- with button ob_start(); woocommerce_simple_add_to_cart(); $button = ob_get_clean(); // modify button so that AJAX add-to-cart script finds it $replacement = sprintf('data-product_id="%d" data-quantity="1" $1 add_to_cart_button product_type_simple ', $product->id); $button = preg_replace('/(class="single_add_to_cart_button)/', $replacement, $button); } } return $button; }
{ $orderby_value = isset($_GET['orderby']) ? woocommerce_clean($_GET['orderby']) : apply_filters('woocommerce_default_catalog_orderby', get_option('woocommerce_default_catalog_orderby')); if ('sku' == $orderby_value) { $args['orderby'] = 'meta_value'; $args['order'] = 'asc'; $args['meta_key'] = '_sku'; } return $args; } add_filter('woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby'); add_filter('woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby'); function custom_woocommerce_catalog_orderby($sortby) { $sortby['sku'] = 'Sort by sku'; return $sortby; } //remove price remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10); remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10); remove_action('woocommerce_single_product_lightbox_summary', 'woocommerce_template_single_price', 10); //remove add to cart remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); remove_action('woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30); remove_action('woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30); remove_action('woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30); remove_action('woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30); remove_action('woocommerce_single_product_lightbox_summary', 'woocommerce_template_single_add_to_cart', 30); $order->add_order_note(sprintf("Shipping label available at: '%s'", $shipment->postage_label->label_url)); //get add to cart form woocommerce_simple_add_to_cart();
function add_to_cart() { woocommerce_simple_add_to_cart(); }