Skip to content

Instantly share code, notes, and snippets.

@spiderflystudios
Last active September 26, 2015 17:22
Show Gist options
  • Select an option

  • Save spiderflystudios/19e3463eeb97213c2cdb to your computer and use it in GitHub Desktop.

Select an option

Save spiderflystudios/19e3463eeb97213c2cdb to your computer and use it in GitHub Desktop.

Revisions

  1. spiderflystudios revised this gist Sep 26, 2015. No changes.
  2. spiderflystudios revised this gist Sep 26, 2015. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  3. spiderflystudios created this gist Sep 26, 2015.
    6 changes: 6 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    // display max quantity allowed if set on single product page
    add_action('woocommerce_single_product_summary', 'maxquantityallowed', 30);
    function maxquantityallowed() {
    if(get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true ) ){
    echo 'Maximum quantity allowed for this product is <strong>'. get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true ) .'</strong>. Request a custom quote for bulk orders.'; }
    }
    11 changes: 11 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // hide quantity box if max quantity is set to one
    add_action('wp_head','hide_quantity_counter');
    function hide_quantity_counter() {
    global $product;
    $product = new WC_Product( get_the_ID() );
    $productcount = get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true );
    // adjust for different product types
    if (($product->is_type( 'bundle' )) || $productcount == 1) { echo '<style> div.bundled_item_cart_content div.bundle_button div.quantity {display:none!important;} </style>'; }
    if (($product->is_type( 'simple' )) || $productcount == 1) { echo '<style> div.quantity {display:none!important;} div.bundled_product div.quantity {display:inherit!important;} </style>'; }
    if (($product->is_type( 'variable' )) || $productcount == 1) { echo '<style> div.variations_button div.quantity {display:none!important;} div.bundled_product div.variations_button div.quantity {display:inherit!important;} </style>'; }
    }