Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active October 3, 2024 13:40
Show Gist options
  • Select an option

  • Save Crocoblock/bcf96e00d54d84f38865d175d01fbe67 to your computer and use it in GitHub Desktop.

Select an option

Save Crocoblock/bcf96e00d54d84f38865d175d01fbe67 to your computer and use it in GitHub Desktop.

Revisions

  1. Crocoblock revised this gist Mar 6, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ public function macros_callback( $args = array() ) {

    $user_id = get_current_user_id();

    if ( ! user_id || ! function_exists( 'WC' ) ) {
    if ( ! $user_id || ! function_exists( 'WC' ) ) {
    return;
    }

  2. Crocoblock revised this gist Feb 20, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    add_action( 'jet-engine/register-macros', function() {

    /**
    * Return purchased and payed products.
    * Return purchased products.
    */
    class Purchased_Products_Macro extends \Jet_Engine_Base_Macros {

    @@ -29,7 +29,7 @@ public function macros_callback( $args = array() ) {

    $args = array(
    'customer_id' => $user_id,
    'limit' => -1,
    'limit' => -1,
    'status' => array(
    'completed',
    ),
  3. Crocoblock revised this gist Feb 20, 2023. 1 changed file with 40 additions and 39 deletions.
    79 changes: 40 additions & 39 deletions purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -1,57 +1,58 @@
    <?php

    add_action( 'jet-engine/register-macros', function() {

    /**
    * Return purchased and payed products.
    */
    class Purchased_Products_Macro extends \Jet_Engine_Base_Macros {
    /**
    * Return purchased and payed products.
    */
    class Purchased_Products_Macro extends \Jet_Engine_Base_Macros {

    public function macros_tag() {
    return 'purchased_products';
    }
    public function macros_tag() {
    return 'purchased_products';
    }

    public function macros_name() {
    return esc_html__( 'Purchased products', 'jet-engine' );
    }
    public function macros_name() {
    return esc_html__( 'Purchased products', 'jet-engine' );
    }

    public function macros_args() {
    return array();
    }
    public function macros_args() {
    return array();
    }

    public function macros_callback( $args = array() ) {
    public function macros_callback( $args = array() ) {

    $user_id = get_current_user_id();
    if ( ! user_id || ! function_exists( 'WC' ) ) {
    return;
    }
    $user_id = get_current_user_id();
    if ( ! user_id || ! function_exists( 'WC' ) ) {
    return;
    }

    $args = array(
    'customer_id' => $user_id,
    'limit' => -1,
    'status' => array(
    'completed',
    ),
    );
    $args = array(
    'customer_id' => $user_id,
    'limit' => -1,
    'status' => array(
    'completed',
    ),
    );

    $orders = wc_get_orders( $args );
    $orders = wc_get_orders( $args );

    $products = array();
    $products = array();

    foreach ( $orders as $order ) {
    foreach ( $orders as $order ) {

    $items = $order->get_items();
    $items = $order->get_items();

    foreach ( $items as $item ) {
    $products[] = $item->get_data()['product_id'];
    }
    foreach ( $items as $item ) {
    $products[] = $item->get_data()['product_id'];
    }

    }
    }

    return implode( ',', $products );
    }
    }
    return implode( ',', $products );
    }
    }

    new Purchased_Products_Macro();

    new Purchased_Products_Macro();

    } );
  4. Crocoblock revised this gist Aug 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ public function macros_callback( $args = array() ) {
    }

    $args = array(
    'customer_id' => get_current_user_id(),
    'customer_id' => $user_id,
    'limit' => -1,
    'status' => array(
    'completed',
  5. Crocoblock revised this gist Jul 19, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,7 @@ public function macros_callback( $args = array() ) {

    $args = array(
    'customer_id' => get_current_user_id(),
    'limit' => -1,
    'status' => array(
    'completed',
    ),
  6. Crocoblock revised this gist Jul 18, 2022. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ public function macros_callback( $args = array() ) {

    $user_id = get_current_user_id();

    if ( ! user_id ) {
    if ( ! user_id || ! function_exists( 'WC' ) ) {
    return;
    }

    @@ -50,9 +50,7 @@ public function macros_callback( $args = array() ) {
    return implode( ',', $products );
    }
    }

    if ( function_exists( 'WC' ) ) {
    new Purchased_Products_Macro();
    }

    new Purchased_Products_Macro();

    } );
  7. Crocoblock revised this gist Jul 18, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    add_action( 'jet-engine/register-macros', function() {

    /**
  8. Crocoblock revised this gist Jul 18, 2022. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,12 @@ public function macros_args() {

    public function macros_callback( $args = array() ) {

    $user_id = get_current_user_id();

    if ( ! user_id ) {
    return;
    }

    $args = array(
    'customer_id' => get_current_user_id(),
    'status' => array(
  9. Crocoblock revised this gist Jul 18, 2022. 1 changed file with 27 additions and 27 deletions.
    54 changes: 27 additions & 27 deletions purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -18,34 +18,34 @@ public function macros_args() {
    }

    public function macros_callback( $args = array() ) {
    $args = array(
    'customer_id' => get_current_user_id(),
    'status' => array(
    'completed',
    ),
    );
    $orders = wc_get_orders( $args );
    $products = array();
    foreach ( $orders as $order ) {
    $items = $order->get_items();
    foreach ( $items as $item ) {
    $products[] = $item->get_data()['product_id'];
    }
    }
    return implode( ',', $products );

    $args = array(
    'customer_id' => get_current_user_id(),
    'status' => array(
    'completed',
    ),
    );

    $orders = wc_get_orders( $args );

    $products = array();

    foreach ( $orders as $order ) {

    $items = $order->get_items();

    foreach ( $items as $item ) {
    $products[] = $item->get_data()['product_id'];
    }

    }

    return implode( ',', $products );
    }
    }
    if ( function_exists( 'WC' ) ) {
    new Purchased_Products_Macro();
    }

    if ( function_exists( 'WC' ) ) {
    new Purchased_Products_Macro();
    }

    } );
  10. Crocoblock created this gist Jul 18, 2022.
    51 changes: 51 additions & 0 deletions purchased-products-macro.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    add_action( 'jet-engine/register-macros', function() {

    /**
    * Return purchased and payed products.
    */
    class Purchased_Products_Macro extends \Jet_Engine_Base_Macros {

    public function macros_tag() {
    return 'purchased_products';
    }

    public function macros_name() {
    return esc_html__( 'Purchased products', 'jet-engine' );
    }

    public function macros_args() {
    return array();
    }

    public function macros_callback( $args = array() ) {

    $args = array(
    'customer_id' => get_current_user_id(),
    'status' => array(
    'completed',
    ),
    );

    $orders = wc_get_orders( $args );

    $products = array();

    foreach ( $orders as $order ) {

    $items = $order->get_items();

    foreach ( $items as $item ) {
    $products[] = $item->get_data()['product_id'];
    }

    }

    return implode( ',', $products );
    }
    }

    if ( function_exists( 'WC' ) ) {
    new Purchased_Products_Macro();
    }

    } );