Last active
May 18, 2020 08:43
-
-
Save huanyichuang/b6def7444a4e609aad1ff60119332618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 使用方式:在頁面中建立 "退貨政策" 後,從 [自訂] 中選取退貨政策的頁面,便會出現在結帳頁中。 | |
* 在 WooCommerce 結帳頁顯示內容。 | |
*/ | |
if ( ! function_exists( 'hyc_refund' ) ) { | |
function hyc_refund() { | |
$pid = get_theme_mod( 'hyc_refund_policy' ); | |
if ( $pid ) { | |
?> | |
<div id="refund" style="overflow-y: scroll; max-height: 10em; margin-bottom: 2em; background: #fff; padding: 15px;"> | |
<h3> | |
<?php echo get_the_title( $pid ); ?> | |
</h3> | |
<?php echo get_the_content( null, false, $pid ); ?> | |
</div> | |
<?php } } | |
} | |
add_action( 'woocommerce_review_order_before_submit', 'hyc_refund', 99 ); | |
/** | |
* 在佈景主題的 [自訂] 功能中,加入新的選項 | |
*/ | |
if ( ! function_exists( 'hyc_refund_customizer' ) ){ | |
function hyc_refund_customizer( $wp_customize ){ | |
$wp_customize -> add_setting( 'hyc_refund_policy', array( | |
'type' => 'theme_mod', | |
'capability' => 'edit_theme_options', | |
'default' => '', | |
'sanitize_callback' => '', | |
'sanitize_js_callback' => '', | |
) ); | |
//設定的頁籤名稱 | |
$wp_customize -> add_section( 'hyc_refund_section', array( | |
'title' => esc_html__('退貨政策', 'text-domain' ) | |
)); | |
//設定的選項名稱 | |
//dropdown-pages 是拿來選頁面用的 | |
$wp_customize -> add_control( 'hyc_refund_policy', array( | |
'label' => esc_html__('退貨政策', 'text-domain' ), | |
'type' => 'dropdown-pages', | |
'capability' => 'edit_theme_options', | |
'section' => 'hyc_refund_section', | |
)); | |
} | |
} | |
add_action( 'customize_register', 'hyc_refund_customizer' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
其實我是寫完之後才想起可以用 Content Block 的做法 XD
(我原本在社團裡說的用 shortcode 的方式就是用 Content Block)