douzepao0281 2018-07-23 02:54
浏览 65
已采纳

如何为woocommerce结帐生成安全代码/密钥?

I am developing a one page order in WordPress with woocommerce as platform. I use jquery ajax to submit the details.

Before I can successfully submit the details of checkout, I must fist go through a url https://www.mywebsite.com/?wc-ajax=update_order_review and initialize these values:

security: hf7f684bw1
postcode: 8000
city: asdas
address: adasd
s_postcode: 8000
s_city: asdas
s_address: asdas
has_full_address: true
post_data: billing_customer_type=Company&billing_company_name=Test&billing_org_nr=123213&billing_address_1=adasd&billing_city=asdas&billing_postcode=8000&billing_phone=1213123&billing_email2=aaa%40gmail.com&_wpnonce=3c1080kf3&_wp_http_referer=%mywebsite%2Fcheckout%2F

This security: hf7f684bw1 value is important so I can submit successfully the checkout details.

Do you know how can I dynamically generate the checkout key/code so that I don't have to manually set it every 24 hours?

  • 写回答

1条回答 默认 最新

  • douze1332 2018-07-23 06:18
    关注

    I was able to solve this issue with the code below:

    <?php
    wp_nonce_field( 'update-order-review', 'update_order_review_nonce', false, true );
    ?>
    

    The code will generate a code with update_order_review_nonce as the name property of the input element.

    Simple explanation:
    The first parameter is a unique name of the action that woocommerce plugin uses. Second parameter is the name of the element. Third parameter ignores the referrer field so I can place and use the key on the page that I prefer.

    The code above can be found on: \woocommerce\includes\class-wc-frontend scripts.php and just find the line 'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ),

    You can use jquery to get the value or whatever will be your purpose.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan