• Resolved amazingtx

    (@amazingtx)


    Currently on our woocommerce site we have used the “woocommerce_proceed_to_checkout” hook to display message to customers using the action..

    add_action( 'woocommerce_proceed_to_checkout', 'order_notice_for_shipping' );
    
    function order_notice_for_shipping() {
    echo '<p class="shipping-info-text">Orders placed at this time will be shipped Monday.</p>';
    }

    Now obviously this is static, and basically what the goal would be is to swap out two different messages (hide one, show the other) based on the Timed Content Settings.

    I’m not sure how to convert these using the Timed Content shortcodes like the above using the woocommerce hooks and get them to work together.

    Could you provide an example using the above existing hook function?

    Thanks!

Viewing 1 replies (of 1 total)
  • Plugin Author Arno Welzel

    (@awelzel)

    What exactly do you want to achieve with “convert these using the Timed Content shortcodes”? Using shortcodes as in the output may not work if the WooCommerce hook is called after WordPress has already processed the shortcodes. But you can just try it – for example add a shortcode to the message so the message will be hidden or shown depending on how the rule is defined:

    add_action( 'woocommerce_proceed_to_checkout', 'order_notice_for_shipping' );
    
    function order_notice_for_shipping() {
    echo '[timed-content-rule id="1"]<p class="shipping-info-text">Orders placed at this time will be shipped Monday.</p>[/timed-content-rule]';
    }

    Instead of id="1" you have to use the real ID of your server side rule of course.

    On the other hand: you already have PHP code and you can already decide in your code what message to output depending on the date/time, so there is no need to use Timed Content at all for this.

    Example – if someone orders on Monday or Tuesday, shipping will be done on Wednesday, otherwise on next Monday:

    add_action( 'woocommerce_proceed_to_checkout', 'order_notice_for_shipping' );
    
    function order_notice_for_shipping() {
      // Get day of week (0=Sunday, 1=Monday and so on)
      $day_of_week = date('w');
    
      if (1 === $day_of_week || 2 === $day_of_week) {
        // Order is done on Monday or Tuesday
        echo '<p class="shipping-info-text">Orders placed at this time will be shipped Wednesday.</p>';
      } else {
        // Order is done on any other day
        echo '<p class="shipping-info-text">Orders placed at this time will be shipped Monday.</p>';
      }
    }

    Or you can also decide not to output any message at all depending on what time the order was placed – it’s all up to you.

    • This reply was modified 2 years, 1 month ago by Arno Welzel.
Viewing 1 replies (of 1 total)
  • The topic ‘How to use with other hooks’ is closed to new replies.