Skip to content

Instantly share code, notes, and snippets.

@huanyichuang
Last active May 18, 2020 08:43
Show Gist options
  • Save huanyichuang/b6def7444a4e609aad1ff60119332618 to your computer and use it in GitHub Desktop.
Save huanyichuang/b6def7444a4e609aad1ff60119332618 to your computer and use it in GitHub Desktop.
<?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' );
@nczz
Copy link

nczz commented May 18, 2020

hyc_refund 方法可以補上判斷,確認是否有設定才觸發。(或是該頁面有內容才顯示)

@nczz
Copy link

nczz commented May 18, 2020

我的做法會是改嵌入 Content Block 讓客戶透過改這 Block 來改那內容。 因為這樣的操作可以避開要開放主題修改權限給客戶,免得把網站改壞XD 算是操作權限考量

@huanyichuang
Copy link
Author

hyc_refund 方法可以補上判斷,確認是否有設定才觸發。(或是該頁面有內容才顯示)

對欸,都忘了這個 XD

@huanyichuang
Copy link
Author

我的做法會是改嵌入 Content Block 讓客戶透過改這 Block 來改那內容。 因為這樣的操作可以避開要開放主題修改權限給客戶,免得把網站改壞XD 算是操作權限考量

其實我是寫完之後才想起可以用 Content Block 的做法 XD
(我原本在社團裡說的用 shortcode 的方式就是用 Content Block)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment