A way for me to remember what my go-to libraries and utilities are.
- HTTP Requests - Guzzle
- Logging - Monolog
| /** | |
| * Determine if the current product should trigger a low stock notification | |
| * | |
| * @param int $product_id - The low stock product id | |
| * | |
| * @since 4.4.0 | |
| */ | |
| if ( false === apply_filters( 'woocommerce_should_send_low_stock_notification', true, $product->get_id() ) ) { | |
| return; | |
| } |
| add_filter( 'gform_field_validation', 'kuztek_first_name_validation', 10, 4 ); | |
| function kuztek_first_name_validation( $result, $value, $form, $field ) { | |
| $first_name_max_length = 10; | |
| $first_name = rgar( $value, $field->id . '.3' ); | |
| if ( $result['is_valid'] && 'name' === $field->type && strlen( $first_name ) > $first_name_max_length ) { | |
| $result['is_valid'] = false; | |
| $result['message'] = 'Please enter a first shorter name'; | |
| } | |
| return $result; | |
| } |
| <?php namespace MyProject; | |
| /** | |
| * Cron Pull | |
| * | |
| * Cron functionality for pulling data on a regular basis | |
| * | |
| * @package MyProject | |
| */ | |
| use WP_Query; |
| function logger($log){ | |
| if ( is_array( $log ) || is_object( $log ) ) { | |
| error_log( print_r( $log, true ) ); | |
| } else { | |
| error_log( $log ); | |
| } |
| /* | |
| * Let's add some more information to the customer details block in admin emails | |
| * This particular example adds the billing country | |
| */ | |
| function mysite_filter_woocommerce_email_customer_details_fields( $fields, $sent_to_admin, $order ) { | |
| if ( $order->billing_country ) { | |
| $fields['billing_country'] = array( | |
| 'label' => __( 'Country', 'woocommerce' ), | |
| 'value' => WC()->countries->countries[ $order->billing_country ], |
| <?php | |
| /* | |
| * This would fit into yourtheme/woocommerce/emails/email-order-details.php and replace the existing loop of totals in there. | |
| */ | |
| if ( $totals = $order->get_order_item_totals() ) { | |
| $i = 0; | |
| foreach ( $totals as $key => $total ) { | |
| $i++; |
| <?php | |
| /** | |
| * Functionality for managing WP Super Cache | |
| */ | |
| /** | |
| * On post save | |
| * |
| public function prepare() { | |
| $data = []; | |
| $total = 0; | |
| // Get the regions | |
| $regions = get_terms( array( | |
| 'taxonomy' => 'naspd_company_region', | |
| 'hide_empty' => true, | |
| ) ); | |
| foreach ( $regions as $region ) { |
| <?php | |
| $questions_wanted = 2000; | |
| $questions_got = 0; | |
| $all_questions = []; | |
| while($questions_got < $questions_wanted){ | |
| $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); | |
| if( count( $questions ) > 0 ){ | |
| foreach($questions as $question): | |
| array_push($all_questions, $question->ID); |