// Remove the default WooCommerce quantity and add to cart button on single products
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
/**
* Add custom back button, quantity, and add to cart section.
*/
function custom_product_action_area() {
global $product; // Get the global product object
// === Back Button ===
// Assuming a simple JavaScript back button. Adjust HTML/URL as needed.
// If you need a specific URL (e.g., to the previous category), this needs more complex logic.
// For now, a simple browser history back button:
echo '';
// You might want to add custom CSS to style this button in wpce-fixes.css
// === Quantity Input ===
// This replicates the default WooCommerce quantity input.
if ( $product && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_type( 'variable' ) ) {
// Only show quantity for simple products (variable products handle quantity in their own form)
woocommerce_quantity_input( array(
'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(), // WPCS: sanitization ok, input var ok.
) );
}
// === Add to Cart Button ===
// This replicates the default WooCommerce add to cart button.
// For simple products, we need to manually call the template
if ( $product && $product->is_type( 'simple' ) ) {
woocommerce_simple_add_to_cart();
} elseif ( $product && $product->is_type( 'external' ) ) {
woocommerce_external_add_to_cart();
} // Variable product 'add to cart' is handled by WPCE directly via a different action,
// so we don't include woocommerce_variable_add_to_cart() here if WPCE handles it.
// If your variable products show a standard WooCommerce variation form, you might need to adjust.
// Add a clearfix or div to ensure these elements don't interfere with the next section's layout
echo '
';
}
// Add our custom function to a position before WPCE filters.
// The priority (e.g., 25) is crucial. Default woocommerce_template_single_add_to_cart is 30.
// WPCE usually inserts its filters around priority 35 or 40.
add_action( 'woocommerce_single_product_summary', 'custom_product_action_area', 25 );
// You will also need to review your wpce-inline-fix.js and wpce-fixes.css to ensure
// they don't have conflicting flexbox rules that would mess with this new order.
// Specifically, the rule for form.cart flexbox might need to be removed or adjusted
// if it's no longer needed for stacking quantity/button below filters.
// However, let's test this PHP first.
12HT welch plug kit Archives - OzWIDE Engine Parts
Skip to content