当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Coupon::set_description方法代码示例

本文整理汇总了PHP中WC_Coupon::set_description方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Coupon::set_description方法的具体用法?PHP WC_Coupon::set_description怎么用?PHP WC_Coupon::set_description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Coupon的用法示例。


在下文中一共展示了WC_Coupon::set_description方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: time

 /**
  * Test coupon reading from the DB.
  * @since 2.7.0
  */
 function test_coupon_read()
 {
     $code = 'coupon-' . time();
     $coupon = new WC_Coupon();
     $coupon->set_code($code);
     $coupon->set_description('This is a test coupon.');
     $coupon->set_usage_count(5);
     $coupon->save();
     $coupon_id = $coupon->get_id();
     $coupon_read = new WC_Coupon($coupon_id);
     $this->assertEquals(5, $coupon_read->get_usage_count());
     $this->assertEquals($code, $coupon_read->get_code());
     $this->assertEquals('This is a test coupon.', $coupon_read->get_description());
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:18,代码来源:data-store.php

示例2: prepare_item_for_database

 /**
  * Prepare a single coupon for create or update.
  *
  * @param WP_REST_Request $request Request object.
  * @return WP_Error|stdClass $data Post object.
  */
 protected function prepare_item_for_database($request)
 {
     global $wpdb;
     $id = isset($request['id']) ? absint($request['id']) : 0;
     $coupon = new WC_Coupon($id);
     $schema = $this->get_item_schema();
     $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props')));
     // BW compat
     if ($request['exclude_product_ids']) {
         $request['excluded_product_ids'] = $request['exclude_product_ids'];
     }
     if ($request['expiry_date']) {
         $request['date_expires'] = $request['expiry_date'];
     }
     // Validate required POST fields.
     if ('POST' === $request->get_method() && 0 === $coupon->get_id()) {
         if (empty($request['code'])) {
             return new WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400));
         }
     }
     // Handle all writable props
     foreach ($data_keys as $key) {
         $value = $request[$key];
         if (!is_null($value)) {
             switch ($key) {
                 case 'code':
                     $coupon_code = apply_filters('woocommerce_coupon_code', $value);
                     $id = $coupon->get_id() ? $coupon->get_id() : 0;
                     $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id);
                     if ($id_from_code) {
                         return new WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400));
                     }
                     $coupon->set_code($coupon_code);
                     break;
                 case 'meta_data':
                     if (is_array($value)) {
                         foreach ($value as $meta) {
                             $coupon->update_meta_data($meta['key'], $meta['value'], $meta['id']);
                         }
                     }
                     break;
                 case 'description':
                     $coupon->set_description(wp_filter_post_kses($value));
                     break;
                 default:
                     if (is_callable(array($coupon, "set_{$key}"))) {
                         $coupon->{"set_{$key}"}($value);
                     }
                     break;
             }
         }
     }
     /**
      * Filter the query_vars used in `get_items` for the constructed query.
      *
      * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
      * prepared for insertion.
      *
      * @param WC_Coupon       $coupon        The coupon object.
      * @param WP_REST_Request $request       Request object.
      */
     return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $coupon, $request);
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:69,代码来源:class-wc-rest-coupons-controller.php

示例3: prepare_item_for_database

 /**
  * Prepare a single coupon for create or update.
  *
  * @param WP_REST_Request $request Request object.
  * @return WP_Error|stdClass $data Post object.
  */
 protected function prepare_item_for_database($request)
 {
     global $wpdb;
     // ID.
     if (isset($request['id'])) {
         $code = $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->posts} WHERE id = %d AND post_type = 'shop_coupon' AND post_status = 'publish'", $request['id']));
         $coupon = new WC_Coupon($code);
     } else {
         $coupon = new WC_Coupon();
     }
     $schema = $this->get_item_schema();
     // Validate required POST fields.
     if ('POST' === $request->get_method() && 0 === $coupon->get_id()) {
         if (empty($request['code'])) {
             return new WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400));
         }
     }
     // Code.
     if (!empty($schema['properties']['code']) && !empty($request['code'])) {
         $coupon_code = apply_filters('woocommerce_coupon_code', $request['code']);
         $id = $coupon->get_id() ? $coupon->get_id() : 0;
         // Check for duplicate coupon codes.
         $coupon_found = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\tWHERE {$wpdb->posts}.post_type = 'shop_coupon'\n\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\t\tAND {$wpdb->posts}.post_title = '%s'\n\t\t\t\tAND {$wpdb->posts}.ID != %s\n\t\t\t ", $coupon_code, $id));
         if ($coupon_found) {
             return new WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400));
         }
         $coupon->set_code($coupon_code);
     }
     // Coupon description (excerpt).
     if (!empty($schema['properties']['description']) && isset($request['description'])) {
         $coupon->set_description(wp_filter_post_kses($request['description']));
     }
     /**
      * Filter the query_vars used in `get_items` for the constructed query.
      *
      * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
      * prepared for insertion.
      *
      * @param stdClass        $data An object representing a single item prepared
      *                                       for inserting or updating the database.
      * @param WP_REST_Request $request       Request object.
      */
     return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $coupon, $request);
 }
开发者ID:pelmered,项目名称:woocommerce,代码行数:50,代码来源:class-wc-rest-coupons-controller.php


注:本文中的WC_Coupon::set_description方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。