Skip to content

Instantly share code, notes, and snippets.

@MahdiAkrami01
Last active October 29, 2024 17:46
Show Gist options
  • Select an option

  • Save MahdiAkrami01/810e328233276a117ccf7880b51dd2c1 to your computer and use it in GitHub Desktop.

Select an option

Save MahdiAkrami01/810e328233276a117ccf7880b51dd2c1 to your computer and use it in GitHub Desktop.

Revisions

  1. MahdiAkrami01 revised this gist Oct 29, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wc-coupon.php
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    *
    * @see https://prnt.sc/zDSJuu5lyHqI
    * @author Mahdi Akrami
    * @url https://x.com/AkramiPro
    * @url https://x.com/AkramiPro
    */
    add_filter( 'get_post_metadata', static function ( $value, $object_id, $meta_key ) {
    if (
  2. MahdiAkrami01 revised this gist Oct 29, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions wc-coupon.php
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@
    *
    * @see https://prnt.sc/zDSJuu5lyHqI
    * @author Mahdi Akrami
    * @url https://x.com/AkramiPro
    */
    add_filter( 'get_post_metadata', static function ( $value, $object_id, $meta_key ) {
    if (
  3. MahdiAkrami01 revised this gist Oct 29, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wc-coupon.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php

    /**
    * Force `Exclude sale items` And `Individual use only` options enabled.
    * Force `Exclude sale items` And `Individual use only` options always enabled.
    *
    * @see https://prnt.sc/zDSJuu5lyHqI
    * @author Mahdi Akrami
  4. MahdiAkrami01 created this gist Oct 29, 2024.
    18 changes: 18 additions & 0 deletions wc-coupon.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <?php

    /**
    * Force `Exclude sale items` And `Individual use only` options enabled.
    *
    * @see https://prnt.sc/zDSJuu5lyHqI
    * @author Mahdi Akrami
    */
    add_filter( 'get_post_metadata', static function ( $value, $object_id, $meta_key ) {
    if (
    in_array( $meta_key, [ 'individual_use', 'exclude_sale_items' ] ) &&
    get_post_type( $object_id ) === 'shop_coupon'
    ) {
    $value = [ 'yes' ];
    }

    return $value;
    }, 9999, 3 );