This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 1: Add a meta box for store stock field | |
function custom_store_stock_meta_box() { | |
add_meta_box( | |
'custom_store_stock_meta_box', // Meta box ID | |
'Store Stock', // Title | |
'render_custom_store_stock_meta_box', // Callback function to render the meta box content | |
'product', // Post type (product for WooCommerce products) | |
'side', // Context (side, normal, advanced) | |
'default' // Priority (high, core, default, low) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('init', 'add_backorder_allowed_role'); | |
function add_backorder_allowed_role() { | |
add_role( | |
'backorder_allowed', | |
__('Backorder Allowed', 'textdomain'), | |
array( | |
'read' => true, // This allows the user to read the content | |
// Add other capabilities as needed | |
) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_before_calculate_totals', 'ensure_two_products_in_cart'); | |
function ensure_two_products_in_cart($cart) { | |
if (is_admin() && !defined('DOING_AJAX')) return; | |
// Replace '123' with the ID of the product you want to ensure is sold in twos | |
$product_id = 123; | |
$quantity_to_add = 2; | |
foreach ($cart->get_cart() as $cart_item_key => $cart_item) { | |
if ($cart_item['product_id'] == $product_id) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function custom_cart_discount() { | |
$discount_percentage = 10; // Replace with your desired discount percentage | |
$cart = WC()->cart; | |
if ( $cart->get_cart_contents_count() >= 2 ) { | |
$discount = $cart->subtotal * ($discount_percentage / 100); | |
$cart->add_fee( 'Bulk Discount', -$discount ); | |
} | |
} | |
add_action( 'woocommerce_cart_calculate_fees', 'custom_cart_discount' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the product object | |
global $product; | |
// Get the regular price | |
$price_per_tile = $product->get_price(); | |
// Get the custom price per square meter (assuming it is stored as a custom field) | |
$price_per_m2 = get_post_meta( $product->get_id(), 'price_per_square_meter', true ); | |
// Display the prices with descriptions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('loop_start', 'list_woocommerce_shipping_zones'); | |
function list_woocommerce_shipping_zones() { | |
if ( current_user_can( 'manage_woocommerce' ) ) { | |
$zones = WC_Shipping_Zones::get_zones(); | |
foreach ($zones as $zone) { | |
echo 'Shipping Zone Name: ' . $zone['zone_name'] . ' | ID: ' . $zone['id'] . '<br>'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function conditionally_hide_local_pickup( $rates, $package ) { | |
$minimum_amount = 50; // Set your minimum order amount here | |
// Get the cart total | |
$cart_total = WC()->cart->get_displayed_subtotal(); | |
// Check if cart total is less than the minimum amount | |
if ( $cart_total < $minimum_amount ) { | |
// Loop through the available shipping methods | |
foreach ( $rates as $rate_id => $rate ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add €40 deposit to the cart based on product ID | |
add_action('woocommerce_cart_calculate_fees', 'add_deposit_fee'); | |
function add_deposit_fee() { | |
if (is_admin() && !defined('DOING_AJAX')) return; | |
$deposit_fee = 40; // Deposit amount | |
$product_ids = array(391); // Replace with your product IDs | |
$add_deposit = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('init', 'custom_add_customer_groups'); | |
function custom_add_customer_groups() { | |
add_role('group1', __('Group 1'), array()); | |
add_role('group2', __('Group 2'), array()); | |
add_role('group3', __('Group 3'), array()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_after_single_product_summary', 'display_on_sale_products_by_brand', 15 ); | |
function display_on_sale_products_by_brand() { | |
global $post; | |
// Get the brands of the current product | |
$brands = wp_get_post_terms( $post->ID, 'brand' ); | |
if ( ! empty( $brands ) && ! is_wp_error( $brands ) ) { | |
foreach ( $brands as $brand ) { |